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;
}

发布了85 篇原创文章 · 获赞 1 · 访问量 1889

猜你喜欢

转载自blog.csdn.net/Tekkenwxp/article/details/103542889