3.1

//3.1#include<iostream>
int main()
{using namespace std;const int in_per_ft=12;cout<<"Enter your height(in inch):__\b\b ";int height; cin>>height;int ft=height/in_per_ft;//ft英尺int in=height%in_per_ft;//in英寸cout<<"Your height is "<<ft<<" feet "<<in<<" inch.\n";cin.get();cin.get();return 0;
}

3.2

//3.2#include<iostream>
#include<cmath>
int main()
{using namespace std;const int in_per_ft=12;//1英尺为12英寸 const double m_per_in=0.0254;//1英寸=0.0254米 const float pound_per_kg=2.2;//1千克=2.2磅 int ft,in;float pound;cout<<"Enter your height(in feet): ___\b\b\b";cin>>ft;cout<<"Enter your height(in inch): ___\b\b\b";cin>>in;cout<<"Enter your weight(in pound): ___\b\b\b";cin>>pound;int height=ft*in_per_ft+in;//计算以英寸为单位的身高 cout<<"Your height is "<<height<<" inch.\n";double height1=height*m_per_in;//计算以米为单位的身高cout<<"Your height is "<<height1<<" meters.\n";float kg=pound/pound_per_kg;//计算以千克为单位的体重cout<<"Your weight is "<<kg<<" kg.\n";float BMI=kg/pow(height1,2);cout<<"BMI= "<<BMI<<endl;cin.get();cin.get();return 0;}

3.3

#include<iostream>
int main()
{using namespace std;const float DToM=60.0;const float MToS=60.0;int d,m,s;//d,m,s分别表示度,分,秒 cout<<"Enter a latitude in degrees, minutes, and seconds:\n";cout<<"First, enter the degrees: ";cin>>d;cout<<"Next, enter  the minutes of arc: ";cin>>m;cout<<"Finally, enter the seconds of arc: ";cin>>s;float n=float (d+m/DToM+s/DToM/MToS);//n表示以度为单位表示 cout<<d<<" degrees, "<<m<<" minutes, "<<s<<" seconds = "<<n<<" degrees\n";cin.get();cin.get();return 0;} 

3.4

//3.4#include<iostream>
int main()
{using namespace std;const int h_per_day=24;const int m_per_h=60;const int s_per_m=60;long second;cout<<"Enter the number of seconds: ";cin>>second;int s=second%s_per_m;int m=second/s_per_m%m_per_h;int h=second/s_per_m/m_per_h%h_per_day;int day=second/s_per_m/m_per_h/h_per_day;cout<<second<<" seconds = "<<day<<" days, "<<h<<" hours, "<<m<<" minutes, "<<s<<" seconds\n";return 0;cin.get();cin.get();
}

3.5

//3.5#include<iostream>
int main()
{using namespace std;cout<<"Enter the world\'s population: ";long long US_population, world_population;cin>>world_population;cout<<"Enter the population of the US: ";cin>>US_population;double percentage=(double)US_population/world_population*100;cout<<"The population of the US is "<<percentage<<"% of the world population.\n";return 0;cin.get();cin.get();
}

3.6

//3.6 汽车耗油量,一加仑的里程 or 每100公里的耗油量(L/100Km) #include<iostream>
int main()
{using namespace std;cout<<"Enter the miles of the distance you have driven: ";double m_distance;//驱车里程(英里) cin>>m_distance;cout<<"Enter the gallons of gasoline you have used: ";double m_gasoline;//汽油量(加仑)cin>>m_gasoline;cout<<"Your car can run "<<m_distance/m_gasoline<<" miles per gallon.\n";cout<<"Computing by European style:\n";cout<<"Enter the kilometers of the distance you have driven: ";double k_distance;//驱车里程(公里)cin>>k_distance;cout<<"Enter the petrol in liters: ";double k_gasoline;//汽油量(升)cin>>k_gasoline;cout<<k_gasoline/k_distance*100<<" L/100Km.\n";return 0;cin.get();cin.get();}

3.7

//3.7 将欧式耗油量(每100公里消耗的汽油量升)转换为美式耗油量(每加仑多少英里)#include<iostream>
int main()
{using namespace std;cout<<"Enter the automobile gasoline consumption figure in European style(liters per 100 kilometers): ";double Euro_style;cin>>Euro_style;cout<<"Converts to U.S. style(miles per gallon): "<<62.14*3.875/Euro_style<<" mpg.\n";return 0;cin.get();cin.get();} 

C++ Primer Plus(第6版) 第3章编程练习相关推荐

  1. C++ Primer Plus第六版第六章编程练习 第4题, 加入Benevolent Order of Programmer后,在BOP大会上

    /*************************************************************************************************** ...

  2. c++ primer plus第六版第六章编程练习

    编写程序读取键盘输入,回显除数字外字符,同时大写转小写,小写转大写,遇'@'就停止. //练习6.1 读取键盘输入,回显输出(除数字),另外大写字母和小写字母互转,遇"@"则退出程 ...

  3. C Primer Plus第六版第七章编程题目与参考答案⭐

    1.编写一个程序读取输入,读到#字符停止,然后报告读取的空格数.换行符数和所有其他字符的数量. #include <stdio.h> #define STOP '#' #define SP ...

  4. C++primer plus第六版第四章编程题代码

    1. #include "stdafx.h" #include <iostream> #include <string> #include <vect ...

  5. C Primer Plus第六版第四章编程题目与参考答案⭐

    1.编写一个程序,提示用户输入名和姓,然后以"名,姓"的格式打印出来. #include <stdio.h>int main() {char firstname[20] ...

  6. C++ Primer Plus 第六版 所有章节课后编程练习答案

    我的独立博客地址:www.blog4jimmy.com,欢迎大家关注 下面的是C++ Primer Plus 第六版所有章节的课后编程练习的答案,都是博主自己写的,有不对的地方请大家留言指出讨论讨论 ...

  7. C Primer Plus第六版第五章运算符,表达式,语句源码

    源码 //5.1#include<stdio.h> #define ADJUST 7.31 int main(void) {const double SCALE = 0.333;doubl ...

  8. C Primer Plus(第六版)第三章 数据和C

    笔记记录 1.float 类型可以储存带小数的数字. 2.printf()中使用%f来处理浮点值.%.2f中的.2用于精确控制输出,指定输出的浮点数只显示小数点后面两位. 3.scanf()函数用于读 ...

  9. c++primer plus 第六版 第六章重点内容总结 以及编程题答案

    1.if中的trick 当char型字符使用cout输出时,并且在使用运算符之后再cout的时候,一定要强制转化回char类型.否则打印出的是数字(字符的编码),if else中的两种操作如果需要多条 ...

  10. C Primer Plus (第六版) 第七章 7.11编程练习 参考答案

    11.ABC 邮购杂货店出售的洋蓟售价为 2.05 美元/磅,甜菜售价为 1.15美元/磅,胡萝卜售价为 1.09美元/磅.在添加运费之前,100美元的订单有5%的打折优惠.少于或等于5磅的订单收取6 ...

最新文章

  1. 一问就想不起来的问题,来看看?
  2. sock使用UDP协议进行广播发送数据
  3. Spring Data ElasticSearch删除索引遇到的java.lang.IllegalStateException: Failed to load ApplicationContext异常
  4. flexbox算法实现_如何使用Flexbox实现水平滚动
  5. eclipse怎么配置python解释器,在Eclipse中配置Pydev Interpreter以使用Enthought Python分发...
  6. AAAI'22 | 基于情感分析的开放域对话系统
  7. 高等数学学习笔记——第五十七讲——平面与直线的位置关系
  8. proteus三输入与门_proteus元件对照
  9. vue 播放.aac格式的音频文件
  10. Spring Cloud CAP 简述
  11. excel中两列如何进行交叉排列组合
  12. 英伟达RTX 4070最新测评来了!光追效果更棒,但仅限于2k游戏
  13. 412.FizzBuzz
  14. 链式前向星dij堆优化
  15. 2022最新阿里云国际注册教程-不用绑定paypal注册
  16. Windows版Docker桌面
  17. 【安全资讯】个人信息保护新规将出台 消费者被短信轰炸将成为历史
  18. Ai 2015 在 win10打开的时候显示 错误:16 解决办法
  19. 淘宝商品详情查询V1新版接口
  20. corda理解(一)

热门文章

  1. [译]Flutter 响应式编程:Steams 和 BLoC 实践范例
  2. 基于jetson nano和yolov5 的车行人检测(二)
  3. 关于2020年12月5日PMI认证考试的报名通知
  4. 【华为机试真题 Python】字符串简单数据解压缩
  5. TX2440 裸跑实验-跑马灯(ADS1.2编译) 入门
  6. UWP 统一平台开发介绍
  7. ESP8266-Arduino编程实例-BMP180气压温度传感器驱动
  8. 2021河南高考编导专业成绩查询,2021河南美术生,统考成绩公布之后怎么办?多少分才能上本科?...
  9. 移动端在线预览pdf,word资源
  10. Multisim Analyses and Simulation的使用(恒流源例子)