【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 ...
随机推荐
- mybaits源码分析(一)
一.源码下载 1.手动编译源码 为了方便在看源码的过程中能够方便的添加注释,可以从官网下载源码编译生成对应的Jar包,然后上传到本地maven仓库,再引用这个Jar. 首先需要编译打包parent项目 ...
- Workflow Core + asp.net core 5.0 实现简单审批工作流
我们知道企业业务系统到处都可以审批工作流的,但也很少有像OA系统一样复杂多级多条件的审批工作流需要设计,所以我们需要一个轻量级的容易上手的workflow框架,通过GitHub,我发现danielge ...
- Redis(一):安装
Ubuntu中使用yum安装redis: sudo apt-get install redis-server # 安装redis,安装完成后会自动启动 ps aux|grep redis # 查看进程 ...
- 备忘:Linux内核编程的几个注意事项
虚拟地址转物理地址要用__pa 内核程序创建的一段地址连续的共享内存,通过内存映射可以让用户态进程存取.之前在RHEL/CentOS的x86_64架构上工作正常.后来在aarch64架构的银河麒麟(L ...
- Spring笔记(3)
一.JDBC Template基本使用 1.开发步骤 1.1直接使用template 导入spring-jdbc和spring-tx坐标 <!-- JDBC--> <dependen ...
- kubernetes部署一个应用程序
文章原文 部署 nginx Deployment 如果你已经完成了Kubernetes的搭建,那我跟我一块来部署第一个应用程序吧.没有完成 Kubernetes 集群搭建的,请参考文档 使用 kube ...
- Vue状态管理Vuex简单使用
状态管理保存在store\index.js中,简单说明如下 import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) export def ...
- DataTable 增加、修改、删除
using System; using System.Data; using System.Windows.Forms; using DotNet.Utilities; namespace Windo ...
- FinallShell连接Centos虚拟机
1.虚拟机下输入ip addr查看网络状态,保证ens33下有ip 2.若没有IP的解决办法 方法一················· 1.输入 cd /etc/sysconfig/network-s ...
- 计算机基础知识以及java JDK、JRE
计算机 计算机(Computer)全称:电子计算机,是一种能够按照程序运行,自动.高速处理海量数据的现代化智能电子设备.由硬件和软件所组成,没有安装任何软件的计算机称为裸机.常见的形式有台式计算机.笔 ...