C++ Primer Plus 第二章 课后编程练习题2-7

2.。。。。。
#include

int main()
{
using namespace std;
int llong;
cout << “请输入一个以long为单位的距离:” << endl;
cin >> llong;
cout << llong << " long单位的距离,等于" << llong*220 << “码” << endl;

return 0;

}

3.。。。。。

#include
using namespace std;
void two(void);
void one(void);
int main()
{
two();
one();
one();

return 0;

}

void two(void)
{
cout << “Three blind mice” << endl;
cout << “Three blind mice” << endl;
}

void one(void)
{
cout << “See how they run” << endl;
}

4.。。。。

#include
using namespace std;

int main()
{
int year;
cout << “请输入你的年龄:” << endl;
cin >> year;
cout << “你的年龄是 " << year << " 包含有 " << year*12 << " 个月。” <<endl;

return 0;

}

5.。。。。
#include
using namespace std;

double fahrenheit(double n);

int main()
{
double css,frht;
cout << “Please enter a Celsius value:”;
cin >> css;
frht = fahrenheit(css);
cout << css <<" degrees Celsius is "
<< frht << " degrees Fahrenheit." << endl;

return 0;

}

double fahrenheit(double n)
{
double frhit = n * 1.8 +32.0;
return frhit;
}

6.。。。。
#include
using namespace std;

int astronomical_units(double ly);
int main()
{
double lyear;
cout << “Enter the number of light years: “;
cin >> lyear;
cout << lyear <<” light years = "
<< astronomical_units(lyear)
<<” astronomical units." <<endl;

return 0;

}

int astronomical_units(double ly)
{
int AU = (int)ly * 63240;

return AU;

}

7.。。。。
#include
using namespace std;
void time(int hours, int minutes);
int main()
{
int hours, minutes;
cout <<"Enter the number of hours: ";
cin >> hours;
cout <<"Enter the number of minutes: ";
cin >> minutes;
time(hours, minutes);

return 0;

}

void time(int hours, int minutes)
{
cout <<“Time: "
<< hours
<<” : "
<< minutes
<< endl;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值