C++ Primer Plus_编程练习_第2章 开始学习C++

朴灿烈づ我的快乐病毒、 2022-11-10 10:58 199阅读 0赞

2.7 编程练习 100

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2FpcXExMzY_size_16_color_FFFFFF_t_70

2.7.1

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. cout << "姓名:神迹小卒\n"
  6. << "地址:四川成都";
  7. return 0;
  8. }
  9. /*>>
  10. 姓名:神迹小卒
  11. 地址:四川成都
  12. */

2.7.2

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. double long_distance;
  6. cout << "请输入一个以long为单位的距离: ";
  7. cin >> long_distance;
  8. cout << long_distance << " long ";
  9. cout << "等于 ";
  10. long_distance *= 220.0;
  11. cout << long_distance << " 码" << endl;
  12. return 0;
  13. }

2.7.3

  1. #include<iostream>
  2. using namespace std;
  3. void print1(void);
  4. void print2(void);
  5. int main()
  6. {
  7. print1();
  8. print1();
  9. print2();
  10. print2();
  11. return 0;
  12. }
  13. void print1(void)
  14. {
  15. cout << "Three blind mice" << endl;
  16. }
  17. void print2(void)
  18. {
  19. cout << "See how they run" << endl;
  20. }
  21. /*>>
  22. Three blind mice
  23. Three blind mice
  24. See how they run
  25. See how they run
  26. */

2.7.4

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int age;
  6. cout << "Enter your age:";
  7. cin >> age;
  8. cout << "your months are:" << age * 12;
  9. return 0;
  10. }
  11. /*>>
  12. Enter your age:29
  13. your months are:348
  14. */

2.7.5

  1. #include <iostream>
  2. using namespace std;
  3. double temperature(double temp);
  4. int main()
  5. {
  6. double celsius;
  7. cout << "Please enter a Celsius value: ";
  8. cin >> celsius;
  9. cout << celsius << " degrees Celsius is ";
  10. cout << temperature(celsius);
  11. cout << " degrees Fahrenheit." << endl;
  12. return 0;
  13. }
  14. double temperature(double temp)
  15. {
  16. return 1.8 * temp + 32.0;
  17. }

2.7.6

  1. #include <iostream>
  2. using namespace std;
  3. double transform(double temp);
  4. int main()
  5. {
  6. double light_years;
  7. cout << "Enter the number of light years: ";
  8. cin >> light_years;
  9. cout << light_years << " light years = ";
  10. cout << transform(light_years);
  11. cout << " astronomical units." << endl;
  12. return 0;
  13. }
  14. double transform(double temp)
  15. {
  16. return temp * 63240.0;
  17. }

2.7.7

  1. #include <iostream>
  2. using namespace std;
  3. void show_time(int hour, int minute);
  4. int main()
  5. {
  6. int hour, minute;
  7. cout << "Enter the number of hours: ";
  8. cin >> hour;
  9. cout << "Enter the number of minutes: ";
  10. cin >> minute;
  11. show_time(hour, minute);
  12. return 0;
  13. }
  14. void show_time(int hour, int minute)
  15. {
  16. cout << "Time: " << hour << ":" << minute << endl;
  17. return;
  18. }

发表评论

表情:
评论列表 (有 0 条评论,199人围观)

还没有评论,来说两句吧...

相关阅读