1 void ch3_1() {
2 using namespace std;
3 unsigned int factor = 12;
4 unsigned int inch, feet;
5 cout << "enter your height in inch:______\b\b\b\b\b\b";
6 cin >> inch;
7 cout << inch / 12 << " feet and " << inch % 12 << " inch" << endl;
8 }
9
10 void ch3_2() {
11 using namespace std;
12 unsigned int feet{0}, inch{0}, pound{0};
13 unsigned int feet2inch{12};
14 double kg2pound{2.2}, inch2meter{0.0254}, meter{0}, kilogram{0};
15 cout << "enter your height in feet&inch and weight in pound" << endl;
16 cout << "feet: "; cin >> feet;
17 cout << "inch: "; cin >> inch;
18 cout << "pound: "; cin >> pound;
19 meter = (feet * feet2inch + inch) * inch2meter;
20 kilogram = pound / kg2pound;
21 cout << "meter: " << meter << endl;
22 cout << "kg: " << kilogram << endl;
23 cout << "BMI: " << kilogram / (meter * meter) << endl;
24 }
25
26 void ch3_3() {
27 using namespace std;
28 const unsigned int factor = 60;
29 unsigned int degrees{0}, minutes{0}, seconds{0};
30 cout << "enter degrees: "; cin >> degrees;
31 cout << "enter minutes: "; cin >> minutes;
32 cout << "enter seconds: "; cin >> seconds;
33 cout << degrees << " degrees, " << minutes << " minutes, " << seconds << " seconds == "
34 << degrees + double(minutes) / factor + double(seconds) / factor / factor << " degrees" << endl;
35 }
36
37 void ch3_4() {
38 using namespace std;
39 unsigned long long secs{0}, secsremain{0};
40 unsigned int days{0}, hours{0}, minutes{0}, seconds{0};
41 cout << "enter seconds: "; cin >> secs;
42 secsremain = secs;
43 days = secsremain / (60 * 60 * 24);secsremain %= (60 * 60 * 24);
44 hours = secsremain / (60 * 60);secsremain %= (60 * 60);
45 minutes = secsremain / 60;secsremain %= 60;
46 cout << secs << " seconds == " << days << " days, "
47 << hours << " hours, " << minutes << " minutes, " << secsremain << " seconds" << endl;
48 }
49
50 void ch3_5() {
51 using namespace std;
52 unsigned long long world_population{0}, usa_population{0};
53 cout << "enter world_population: "; cin >> world_population;
54 cout << "enter usa_population: "; cin >> usa_population;
55 cout << double(usa_population) / double(world_population) * 100 << '%' << endl;
56 }
57
58 void ch3_6() {
59 using namespace std;
60 unsigned int km{0}, L{0};
61 cout << "enter km: "; cin >> km;
62 cout << "enter L: "; cin >> L;
63 cout << double(L) / km * 100 << "L/100km" << endl;
64 }
65
66 void ch3_7() {
67 using namespace std;
68 double Lp100km{0}, mpg{0};
69 cout << "eu L/100km: "; cin >> Lp100km;
70 cout << "to mpg: " << 1 / (Lp100km / 3.875 / 62.14) << endl;
71 }

【C++ Primer Plus】编程练习答案——第3章的更多相关文章

  1. 【C++ Primer Plus】编程练习答案——第12章

    1 // chapter12_1_cow.h 2 3 4 #ifndef LEARN_CPP_CHAPTER12_1_COW_H 5 #define LEARN_CPP_CHAPTER12_1_COW ...

  2. 【C++ Primer Plus】编程练习答案——第11章 (待更新)

    最近开学,事情较多,过两天更新...

  3. 【C++ Primer Plus】编程练习答案——第10章

    1 // chapter10_1_account.h 2 3 #ifndef LEARN_CPP_CHAPTER10_1_ACCOUNT_H 4 #define LEARN_CPP_CHAPTER10 ...

  4. 【C++ Primer Plus】编程练习答案——第9章

    1 // chapter09_golf.h 2 3 #ifndef LEARN_CPP_CHAPTER09_GOLF_H 4 #define LEARN_CPP_CHAPTER09_GOLF_H 5 ...

  5. 【C++ Primer Plus】编程练习答案——第8章

    1 void ch8_1_print(const std::string & str, int n = 0 ) { 2 using namespace std; 3 static int fl ...

  6. 【C++ Primer Plus】编程练习答案——第7章

    1 double ch7_1_harmonicaverage(double a, double b) { 2 return 2 / (1 / a + 1 / b); 3 } 4 5 void ch7_ ...

  7. 【C++ Primer Plus】编程练习答案——第6章

    1 void ch6_1() { 2 using namespace std; 3 char ch; 4 while ((ch = cin.get()) != '@') { 5 if (isdigit ...

  8. 【C++ Primer Plus】编程练习答案——第5章

    1 void ch5_1() { 2 using namespace std; 3 int small, big, sum{0}; 4 cout << "enter small ...

  9. 【C++ Primer Plus】编程练习答案——第4章

    1 void ch4_1() { 2 using namespace std; 3 string fname, lname; 4 char grade; 5 unsigned int age; 6 c ...

随机推荐

  1. web.xml中自定义Listener

    Listener可以监听容器中某一执行动作,并根据其要求做出相应的响应. 常用的Web事件的监听接口如下: ServletContextListener:用于监听Web的启动及关闭 ServletCo ...

  2. ubuntu下配置JDK的一些坑点

    ubuntu下配置JDK的一些坑点 在centos下的JDK配置: 在ubuntu下的话,要修改两个地方: 在/etc/enviornment中配置! 在/etc/profile中配置! 写在最后: ...

  3. jQuery中ajax请求的六种方法(三、五):$.getScript()方法

    5.$.getScript()方法 <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...

  4. Servlet体系及方法

    时间:2016-11-11 15:07 --Servlet体系Servlet(interface):    实现类:GenericServlet.HttpServletServletConfig(in ...

  5. HbaseWAL

    1.WAL意为 Write Ahead Log ,类似MySQL中的binlog,用来做灾难恢复之用,HLog记录数据的所有变更,一旦数据修改,就可以从Log中进行恢复. Hbase采用类LSM的架构 ...

  6. JavaScript——数组——数组长度

    JavaScript--数组--数组长度 JavaScript中的数组长度是可变的,可用赋值运算符改变数组大小,如果改变之后的数组的长度比原数组大,则新数组会在末尾补充相应数量的空位,空位上的数组元素 ...

  7. JavaWeb中表单数据的获取及乱码问题

    首先使用一个用户提交界面作为举例(文本框,密码框,选择,下拉表单等),效果如下 注:HTML < form> 标签的 action 属性,其定义和用法是: 属性值为URL,表示向何处发送表 ...

  8. IO流学习笔记(二)之BufferedWriter与BufferedReader及实例Demo

    在之前的学习笔记(http://blog.csdn.net/megustas_jjc/article/details/72853059)中,FileWriter与FileReader的Demo使用的中 ...

  9. introduction-to-64-bit-assembly

    introduction-to-64-bit-assembly NASM - The Netwide Assembler x86-64 下函数调用及栈帧原理 汇编语言基本概念简介 mycode

  10. Redis++:Redis 内存爆满 之 淘汰策略

    前言: 我们的redis使用的是内存空间来存储数据的,但是内存空间毕竟有限,随着我们存储数据的不断增长,当超过了我们的内存大小时,即在redis中设置的缓存大小(maxmeory 4GB),redis ...