【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 ...
随机推荐
- 1 TortoiseGit简介
tortoiseGit是一个开放的git版本控制系统的源客户端,支持Winxp/vista/win7.该软件功能和git一样 不同的是:git是命令行操作模式,tortoiseGit界面化操作模式,不 ...
- 深入浅出Mybatis系列(三)---配置简介(mybatis源码篇)
上篇文章<深入浅出Mybatis系列(二)---Mybatis入门>写了一个Demo简单体现了一下Mybatis的流程.本次,将简单介绍一下Mybatis的配置文件: 上次例子中,我们以 ...
- [ASP.NET MVC]@Scripts.Render、@Styles.Render的使用
一.配置BundleConfig.cs文件 1.首先要在App_Start 里面BundleConfig.cs 文件里面 添加要包含的css文件 2.BundleConfig就是一个微软新加的 一个打 ...
- idea项目在maven projects中显示灰色的解决办法。建新建module src变成标准的文件夹
在使用idea的过程中,有时会遇到其中一个maven模块变成灰色(可以通过view - tool windows -> maven projects 现实),如下所示: 造成这个的原因可能是忽略 ...
- JDBC基础篇(MYSQL)——通过JDBC连接数据库的三种方式
package day01_jdbc; import java.sql.Connection; import java.sql.Driver; import java.sql.DriverManage ...
- TOMCAT WEB请求乱码
post乱码: 原因: 对于POST方式,它采用的编码是由页面来决定的即ContentType("text/html; charset=GBK").当通过点击页面的submit ...
- Pytest系列(15)- 多重校验插件之pytest-assume的详细使用
如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 pytest中可以用pyth ...
- Git 系列教程(3)- 初次运行 Git 前的配置
前言 直接搬官网教程,再修改下,先啰嗦可以直接看以前的文章 Window初始化Git环境 https://www.cnblogs.com/poloyy/p/12185132.html Linux初始化 ...
- C# HttpWebResponse 请求常见的状态码
Accepted 202 等效于 HTTP 状态 202. Accepted 指示已接受请求做进一步处理. AlreadyReported 208 等效于 HTTP 状态 208. AlreadyRe ...
- ysoserial CommonsColletions7分析
CC7也是一条比较通用的链了,不过对于其原理的话,其实还是挺复杂的.文章如有错误,敬请大佬们斧正 CC7利用的是hashtable#readObject作为反序列化入口.AbstractMap的equ ...