【第二章】C++ Primer plus 的编程练习题(选取部分)
2018-01-25 14:22
381 查看
/*********************************** 2017年9月23日13:12:16 Athor:xiyuan255 Course:C++ Contain:myfirst.cpp Reference: C++ Primer plus 说明:C++ Primer plus第二章的练习题(选取部分) 【 P35 】 *************************************/ // review2.cpp -- C++ Primer plus 第二章练习题 #include <iostream> void ageToMonth(void); void temperatureFunc(void); void timeFunc(void); using namespace std; int main(void) { //ageToMonth(); // test 1 //temperatureFunc(); // test 2 timeFunc(); // test 3 return 0; } void ageToMonth(void) { cout << "Enter your age: "; int age; cin >> age; cout << age << " age = " << (age*12) << " month." << endl; } /** 输出结果: Enter your age: 29 29 age = 348 month. */ int celsiusToFahrenheit(int celsius) { return (int)(celsius * 1.8 + 32.0); } void temperatureFunc(void) { cout << "Please enter a Celsius value: "; int celsius; cin >> celsius; int fahrenheit; fahrenheit = celsiusToFahrenheit(celsius); cout << celsius << " degrees Celsius is " << fahrenheit << " degrees Fahrenheit.\n"; } /** 输出结果: Please enter a Celsius value: 20 20 degrees Celsius is 68 degrees Fahrenheit. */ void hoursAndMinutesToTime(int hours, int minutes) { cout << "Time: " << hours << ":" << minutes << endl; } void timeFunc(void) { cout << "Enter the number of hours: "; int hours; cin >> hours; cout << "Enter the number of minutes: "; int minutes; cin >> minutes; hoursAndMinutesToTime(hours, minutes); } /** 输出结果: Enter the number of hours: 9 Enter the number of minutes: 28 Time: 9:28 */
相关文章推荐
- 【第三章】C++ Primer plus 的编程练习题(选取部分)
- 【第四章】C++ Primer plus 的编程练习题(选取部分)
- 【第五章】C++ Primer plus 的编程练习题(选取部分)
- 【第六章】C++ Primer plus 的编程练习题(选取部分)
- 【第八章】C++ Primer plus 的编程练习题(选取部分)
- 【第十五章】C++ Primer plus 的编程练习题
- c++ primer plus 第六版第二章编程练习答案
- 【第十七章】C++ Primer plus 的编程练习题
- 【第十八章】C++ Primer plus 的编程练习题
- C++ primer plus(中文版) 第五章编程练习题
- C++ Primer Plus(第五版)第五章编程练习题6(关于string难点哦)
- C++ Primer Plus课后编程练习——第七章 函数-C++的编程模块(部分)
- C++ Primer Plus 编程练习 第二章
- 【第九章】C++ Primer plus 的编程练习题
- c++ primer plus(第6版)中文版 第二章编程练习答案
- 《C Primer Plus》(第五版)第二章编程练习题源代码
- 【第十一章】C++ Primer plus 的编程练习题
- C++ Primer Plus第二章课后编程答案
- 【第十二章】C++ Primer plus 的编程练习题
- C++ Primer Plus第六版 第二章 编程练习答案