c++primer plus 第六版 第2章 编程练习之路

//c++ Primer Plus(习题2.2)

//input 以 long为单位的距离,将它转换成码.(1 long =220码)
#include<iostream>

const float Yard = 220;
int main()
{
	using namespace std;
	cout<< "Input distance by long:";
	float result;
	cin >> result;
	cout << result << "long change to Yard is " << result*Yard << endl;
	return 0;
}

//c++ Primer Plus(习题2.3)

//use function twice,input some sentence!
#include<iostream>
void printf1(...); //不带参数列表的要用...
void printf2(...);
using namespace std;
int main(void)
{
	printf1();
	printf1();
	printf2();
	printf2();
	return 0;
}
void printf1(...)
{
	cout << "Three blind mice\n";
}
void printf2(...)
{
	cout << "See how they run\n";
}

//c++ Primer Plus(习题2.4)

//Input ages,Output how many mouths!
#include<iostream>
const int Years = 12;
int main(void)
{
	using namespace std;
	cout << "Enter your age: ";
	int ages;
	cin >> ages;
	cout << "You live " << ages*Years << " months!\n"<<"Bye!";
	return 0;
}
//c++ Primer Plus(习题2.5)

//Input Celsius dgree tranform to Fahrenheit
#include<iostream>
using namespace std;
double Celsius_Fahrenheit(double degree);
int main(void)
{
cout << "Please enter a Celsious value: ";
double value,result;
cin >> value;
result=Celsius_Fahrenheit(value);
cout << value << " degree Celsius is " << result << " degrees Fahrenheit.\n";
return 0;
}
double Celsius_Fahrenheit(double degree)
{
return degree*1.8 + 32.0;
}

//c++ Primer Plus(习题2.6)

//以光年值为参数,返回对应天文单位的值
#include<iostream>
using namespace std;
double light_astronomical(double years);
int main(void)
{
	cout << "Enter the number of light years: ";
	double lightyears, result;
	cin >> lightyears;
	result =light_astronomical(lightyears);
	cout << lightyears << " light years= " << result << " astronomical units.\n";
	return 0;
}
double light_astronomical(double years)
{
	return years*63240; //1光年=63240天文单位
}


//c++ Primer Plus(习题2.7)

//Input hours and minutes,follow text;
#include<iostream>
using namespace std;
void hours_minutes
(
int hours,int minutes);
int main(void)
{
	cout << "Enter the number of hours: ";
	int Hours, Minutes;
	cin >> Hours;
	cout << "Enter the number of minute: ";
	cin >> Minutes;
	hours_minutes(Hours,Minutes);
	return 0;
}
void hours_minutes(int hours,int minutes)
{
	cout << "Time: " << hours << ":" << minutes<<endl;
}


未完待续。。。。。。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值