【C++ Primer Plus】编程练习答案——第3章
 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章的更多相关文章
- 【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 ... 
- 【C++ Primer Plus】编程练习答案——第11章 (待更新)
		最近开学,事情较多,过两天更新... 
- 【C++ Primer Plus】编程练习答案——第10章
		1 // chapter10_1_account.h 2 3 #ifndef LEARN_CPP_CHAPTER10_1_ACCOUNT_H 4 #define LEARN_CPP_CHAPTER10 ... 
- 【C++ Primer Plus】编程练习答案——第9章
		1 // chapter09_golf.h 2 3 #ifndef LEARN_CPP_CHAPTER09_GOLF_H 4 #define LEARN_CPP_CHAPTER09_GOLF_H 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 ... 
- 【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_ ... 
- 【C++ Primer Plus】编程练习答案——第6章
		1 void ch6_1() { 2 using namespace std; 3 char ch; 4 while ((ch = cin.get()) != '@') { 5 if (isdigit ... 
- 【C++ Primer Plus】编程练习答案——第5章
		1 void ch5_1() { 2 using namespace std; 3 int small, big, sum{0}; 4 cout << "enter small ... 
- 【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 ... 
随机推荐
- Qt简单的解析Json数据例子(一)
			要解析的json的格式为: { "rootpath": "001", "usernum": 111, "childdep" ... 
- Json 文件 : 出现 Expected value at 1:0 问题的解决
			只要找一个json在线解析,验证你的json文件格式的正确性,错误可以忽略. 如要消除红叉,关闭Json Validation即可,如下操作: 
- docker安装与配置gitlab详细过程
			docker安装与配置gitlab详细过程 1.打开网易镜像中心 https://c.163yun.com/hub#/m/home/ 2.搜索gitlab,获取下载地址.例如:docker pull ... 
- python matplotlib 绘图+显示数值
			参考:https://www.jb51.net/article/152685.htm 用plt.text函数 import numpy as np import matplotlib.mlab as ... 
- golang GC 垃圾回收机制
			垃圾回收(Garbage Collection,简称GC)是编程语言中提供的自动的内存管理机制,自动释放不需要的对象,让出存储器资源,无需程序员手动执行. Golang中的垃圾回收主要应用三色标记法, ... 
- Typora代码块配色和标题自带序号的实现代码
			Typora代码块配色和标题自带序号的实现代码 先打开主题文件夹 文件>偏好设置>外观>打开主题文件夹 然后编辑base.user.css(如果没有就新建一个)文件 /*标题自动添加 ... 
- 五分钟搞懂MySQL索引下推
			大家好,我是老三,今天分享一个小知识点--索引下推. 如果你在面试中,听到MySQL5.6"."索引优化" 之类的词语,你就要立马get到,这个问的是"索引下推 ... 
- noip模拟30
			\(\color{white}{\mathbb{缀以无尽之群星点点,饰以常青之巨木郁郁,可细斟木纹叶脉,独无可极苍穹之览,名之以:密林}}\) 看完题后感觉整套题都没什么思路,而且基本上整场考试确实是 ... 
- docker日常使用指南
			docker日常使用指南 目录 docker日常使用指南 前言 1.基础知识 1.1 docker是什么 1.2 与虚拟机(VM)的区别 1.3 镜像与容器 2.安装 2.1 在线安装 2.2 离线安 ... 
- 《Go语言圣经》阅读笔记:第二章程序结构
			第二章 程序结构 2.1 命名 在GO语言中,所有的变量名.函数.常量.类型.语句标号.包名都遵循一个原则: 名字必须以字母或者下划线开头,后面紧跟任意数量的字母数字下划线.区分大小写. 在GO语言中 ... 
