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. 如何在指定的地址上创建C++对象

    如果已经掌握在静态存储区上创建对象的方法,那么可以扩展一下,可以在任意地址上创建C++对象. 解决方案:-在类中重载new/delete操作符-在new的操作符重载函数中返回指定的地址-在delete ...

  2. 【C#】Enum,Int,String的互相转换 枚举转换

    Enum为枚举提供基类,其基础类型可以是除 Char 外的任何整型.如果没有显式声明基础类型,则使用 Int32.编程语言通常提供语法来声明由一组已命名的常数和它们的值组成的枚举. 注意:枚举类型的基 ...

  3. 修改IDEA默认模板

    然后找到你想要修改的模板就可以了

  4. Python 3.10 is coming!

    看看Python 官网的文档 whatsnew,Python 3.10 已然距离我们越来越近了,然我们看看 Python 3.10 相较于 Python 3.9 有哪些改变吧 新特性 通过括号来组织多 ...

  5. dpkg:处理 xxx (--configure)时出错解决办法,也可用于卸载软件出错的情况

    dpkg:处理 xxx (--configure)时出错解决办法今早安装nfs时出现问题,找到该文,备份留用.然后在网上找到了这片文章,按步骤走就解决了,中间会提示自动卸载一下,执行那个命令就好了,我 ...

  6. 三.Go微服务--令牌桶实现原理

    1. 前言 在上一篇文章 Go微服务: 令牌桶 当中简单的介绍了令牌桶实现的原理,然后利用 /x/time/rate 这个库 10 行代码写了一个基于 ip 的 gin 限流中间件,那这个功能是怎么实 ...

  7. i++ ++i 理解

    i++与++i怎么运算,解决办法: i++规则是在表达式中先取i的值使用,后让i的值变化成加1后的值. 举例:如在式中 j=i++,他就会变成这样的两步,第一步先执行j=i,第二步执行i=i+1. + ...

  8. MySQL——优化

    MySQL数据库优化: 1.优化角度 安全: 数据可持续性 性能: 数据的高性能访问 2.优化范围(优化顺序---->) (1)存储.主机和操作系统: 主机架构稳定性 I/O规划及配置 swap ...

  9. FlinkCDC 2.0使用实践体验

    一.背景说明 所谓CDC:全称是 Change Data Capture ,在广义的概念上,只要能捕获数据变更的技术,我们都可以称为 CDC .通常我们说的 CDC 技术主要面向数据库的变更,是一种用 ...

  10. 事务保存点savepoint

    一.