C++ Primer Plus 编程练习——第2章

Posted 开心果壳好硬

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C++ Primer Plus 编程练习——第2章相关的知识,希望对你有一定的参考价值。

 1 void ch2_1() {
 2     using namespace std;
 3     cout << "xxxxxxxx" << endl;
 4 }
 5 
 6 void ch2_2() {
 7     using namespace std;
 8     double num;
 9     cout << "please input a distance in long: ";
10     cin >> num;
11     cout << "it equals " << num * 220 << endl;
12 }
13 
14 void ch2_3_1() {
15     using namespace std;
16     cout << "Three blind mice" << endl;
17 }
18 
19 void ch2_3_2() {
20     using namespace std;
21     cout << "See how they run" << endl;
22 }
23 
24 void ch2_3() {
25     using namespace std;
26     ch2_3_1();ch2_3_1();
27     ch2_3_2();ch2_3_2();
28 }
29 
30 void ch2_4() {
31     using namespace std;
32     unsigned int age;
33     cout << "enter your age: ";
34     cin >> age;
35     cout << "months: " << age * 12 << endl;
36 }
37 
38 double ch2_5_1(double c){
39     using namespace std;
40     return c * 1.8 + 32;
41 }
42 
43 void ch2_5() {
44     using namespace std;
45     double c;
46     cout << "enter a celsius value: ";
47     cin >> c;
48     cout << c << "degrees Celsius is " << ch2_5_1(c) << " degrees Fahrenheit" << endl;
49 }
50 
51 double ch2_6_1(double lyear){
52     return lyear * 63240;
53 }
54 
55 void ch2_6() {
56     using namespace std;
57     double lyear;
58     cout << "enter the number of light years: ";
59     cin >> lyear;
60     cout << lyear << " light years = " << ch2_6_1(lyear) << " astronomical units" << endl;
61 }
62 
63 void ch2_7_1(unsigned int h, unsigned int m){
64     using namespace std;
65     cout << "Time: " << h << ":" << m << endl;
66 }
67 
68 void ch2_7() {
69     using namespace std;
70     unsigned int h, m;
71     cout << "enter the number of hours: ";
72     cin >> h;
73     cout << "enter the number of minutes: ";
74     cin >> m;
75     ch2_7_1(h, m);
76 }

 

以上是关于C++ Primer Plus 编程练习——第2章的主要内容,如果未能解决你的问题,请参考以下文章

C++ Primer Plus编程练习答案——第9章

C++ Primer Plus编程练习答案——第13章

C++ Primer Plus编程练习答案——第10章

C++ Primer Plus编程练习答案——第14章

C++ Primer Plus编程练习答案——第8章

C Primer Plus(第6版)—第4章编程练习