c++ primer plus第二章习题答案(原创请参考)
2014-11-25 12:54
441 查看
第一次发微博不知道发点什么内容,就把以前写的一些小程序发上来先垫个底吧。
程序在visual studio下运行正常,其他编译器下没试过。如果有什么漏洞,还请各位不吝赐教。
没怎么写注释,这几天时间紧,以后慢慢补上。
第一题
第二题
第三题
第四题
第五题
第六题
第七题
程序在visual studio下运行正常,其他编译器下没试过。如果有什么漏洞,还请各位不吝赐教。
没怎么写注释,这几天时间紧,以后慢慢补上。
第一题
#include <iostream> //using namespace std;// choose either this one or "using std::..." int main() { using std::cout; using std::endl; cout << "My name is MiaoXingRen" << endl; cout << "My address is No.92 of XIDAZHI street of Harbin, Heilongjiang, China" << endl; return 0; }
第二题
#include <iostream> using namespace std; int Convert(int dis); int main() { int distan_long, distan_ma; cout << "Please input the distance with the unit 'long':"; cin >> distan_long; distan_ma = Convert(distan_long); cout << "The distance you have input is " << distan_long << " in the unit long, "; cout << "equals to " << distan_ma << " in the unit ma." << endl; return 0; } int Convert(int dis) { int a; return (dis * 220); }
第三题
#include <iostream> using namespace std; void Output1(void); void Output2(void); int main() { Output1(); Output1(); Output2(); Output2(); return 0; } void Output1(void) { cout << "Three blind mice" << endl; } void Output2(void) { cout << "See how they run" << endl; }
第四题
#include <iostream> using namespace std; int Convert(int year); int main() { int year, month; cout << "Enter your age: "; cin >> year; month = Convert(year); cout << "Your age contains " << month << " months" << endl; return 0; } int Convert(int year) { return (year * 12); }
第五题
#include <iostream> using namespace std; double Convert(int C); int main() { int centigrade; double fahrenheit; cout << "Please enter a Celsius value: "; cin >> centigrade; fahrenheit = Convert(centigrade); cout << centigrade << " degrees Celsius is "; cout << fahrenheit << " degrees Fahrenheit." << endl; return 0; } double Convert(int C) { double F; F = (double)C * 1.8 + 32.0; return F; }
第六题
#include <iostream> using namespace std; double Convert(double ly); int main() { double light_year, astron_unit; cout << "Enter the number of light years: "; cin >> light_year; astron_unit = Convert(light_year); cout << light_year << " light years = "; cout << astron_unit << " astronomical units."; cout << endl; return 0; } double Convert(double ly) { double au; au = ly * 63240; return au; }
第七题
#include <iostream> using namespace std; void Format(int hour, int min); int main() { int hour, minute; cout << "Enter the number of hours: "; cin >> hour; cout << "Enter the number of minutes: "; cin >> minute; Format(hour, minute); return 0; } void Format(int hour, int min) { cout << "Time: " << hour << ":" << min << endl; }
相关文章推荐
- C++ Primer Plus (第6版)课后习题答案 第二章
- C++ primer plus 第十章课后习题,原创答案。
- C++Primer Plus笔记——第二章 开始学习C++及课后习题答案
- c++ primer plus第八章习题答案
- C++ primer plus(第六版)学习笔记、习题答案(4)
- c++ primer plus 第六版第二章编程练习答案
- c++ primer plus(第6版)中文版 第二章编程练习答案
- c++ primer plus第十一章习题答案
- c++ primer plus第九章习题答案
- C++ Primer Plus (第六版)第六章编程练习参考答案
- C++Primer第五版 第二章习题答案(11~20)
- c++ primer plus第三章习题答案
- C++ Primer Plus第六版 第二章 编程练习答案
- 《C++ Primer Plus(第六版)》(1)(第二章 开始学习C++ 笔记和答案)
- c++ primer plus第六章习题答案
- C++ primer plus(第六版)学习笔记、习题答案(3)
- c++ primer plus第十章习题答案
- C++ primer plus(第六版)学习笔记、习题答案(1)
- C++primer plus(第四版)第五章习题参考
- c++primer plus 第八章习题答案(自己写的)