【第三章】C++ Primer plus 的编程练习题(选取部分)
2018-01-31 09:05
501 查看
/*********************************** 2017年9月26日16:56:31 Athor:xiyuan255 Course:C++ Contain:myfirst.cpp Reference: C++ Primer plus 说明:C++ Primer plus第三章的练习题(选取部分) 【 P69 】 *************************************/ // review3.cpp -- C++ Primer plus 第三章练习题 #include <iostream> using namespace std; void exampleNo2(void); void exampleNo3(void); void exampleNo4(void); void exampleNo7(void); int main(void) { //exampleNo2(); // example 2 test //exampleNo3(); // example 3 test //exampleNo4(); // example 4 test exampleNo7(); // example 7 test return 0; } void exampleNo7(void) { cout << "请按欧洲风格输入汽车的耗油率(升/100km):"; double mile_kilome; cin >> mile_kilome; const double Litre = 3.875; const double Mile = 62.14; double gallon = mile_kilome / Litre; int mpg = int(Mile / gallon); cout << "转化成美国风格的耗油量(每加仑多少英里):" << mpg << "mpg.\n"; } /** 输出结果: 请按欧洲风格输入汽车的耗油率(升/100km):12.41 转化成美国风格的耗油量(每加仑多少英里):19mpg. */ void exampleNo4(void) { cout << "Enter the number of seconds: "; long long seconds; cin >> seconds; const short Hour = 24; const short Minute = 60; const short Second = 60; int days = seconds / (Hour * Minute * Second); int hours = seconds % (Hour * Minute * Second) / (Minute * Second); int mintes = (seconds % (Hour * Minute * Second)) % (Minute * Second) / Second; int second = seconds % Second; cout << seconds << " seconds = " << days << " days, " << hours << " hours, " << mintes << " mintues, " << second << " seconds.\n"; } /** 输出结果: Enter the number of seconds: 31600000 31600000 seconds = 365 days, 17 hours, 46 mintues, 40 seconds. */ void exampleNo3(void) { cout << "Enter a latitude in degrees, minutes and seconds: \n"; cout << "First, enter the degrees: "; int degrees; cin >> degrees; cout << "Next, enter the minutes of arc: "; int minutes; cin >> minutes; cout << "Finally, enter the seconds of arc: "; int seconds; cin >> seconds; const int Minute = 60; const int Second = 60; double degre = double(degrees) + double((double)minutes/Minute) + double((double)seconds/(Second * Minute)); cout << degrees << " degrees, " << minutes << " mintes, " << seconds << " seconds = " << degre << " degrees.\n"; } /** 输出结果: Enter a latitude in degrees, minutes and seconds: First, enter the degrees: 37 Next, enter the minutes of arc: 51 Finally, enter the seconds of arc: 19 37 degrees, 51 mintes, 19 seconds = 37.8553 degrees. */ void exampleNo2(void) { cout << "以几英尺几英寸的方式输入身高," << "并以磅为单位输入其体重:\n"; cout << "英尺:"; int feets = 0; cin >> feets; cout << "英寸:"; int inchs = 0; cin >> inchs; cout << "体重:"; int pounds; cin >> pounds; const short British = 12; const float Metric = 0.0254f; const float Pound = 2.2f; double meter = double (Metric * (feets * British + inchs)); double kilogram = double (pounds / Pound); double BMI = double (pow(kilogram/meter, 2)); cout << "meter = " << meter << ", kilogram = " << kilogram << endl; cout << "BMI = " << BMI << " Done!\n"; } /** 输出结果: 以几英尺几英寸的方式输入身高,并以磅为单位输入其体重: 英尺:5 英寸:10 体重:130 meter = 1.778, kilogram = 59.0909 BMI = 1104.53 Done! */
相关文章推荐
- 【第四章】C++ Primer plus 的编程练习题(选取部分)
- 【第五章】C++ Primer plus 的编程练习题(选取部分)
- 【第六章】C++ Primer plus 的编程练习题(选取部分)
- 【第八章】C++ Primer plus 的编程练习题(选取部分)
- 【第二章】C++ Primer plus 的编程练习题(选取部分)
- 【第十四章】C++ Primer plus 的编程练习题
- C++ Primer Plus课后编程练习——第七章 函数-C++的编程模块(部分)
- C++ Primer Plus第五版 第三章 编程练习答案
- c++ primer plus 第六版第三章编程练习答案
- 【第十五章】C++ Primer plus 的编程练习题
- C++Primer Plus 第三章编程练习个人答案
- 【第十七章】C++ Primer plus 的编程练习题
- 【第十八章】C++ Primer plus 的编程练习题
- c++ primer plus(第6版)中文版 第三章编程练习答案
- C++ Primer Plus(第五版)第五章编程练习题6(关于string难点哦)
- C++ Primer Plus 编程练习 第三章
- C++ Primer Plus第六版 第三章 编程练习答案
- 【第九章】C++ Primer plus 的编程练习题
- 《C Primer Plus》(第五版)第三章编程练习题源代码
- C++ Primer Plus第三章课后编程答案