当前位置: 首页 > news >正文

C++ Primer Plus(第6版) 第3章编程练习

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();} 

http://www.taodudu.cc/news/show-5435435.html

相关文章:

  • Linux的基础指令
  • 代码随想录——二叉树的层序遍历Ⅱ(Leetcode107)
  • 杨校老师项目之基于51单片机的汽车智能照明系统【嵌入式】
  • ospf基础
  • iOS 学习资料
  • Co-Driver:基于 VLM 的自动驾驶助手,具有类人行为并能理解复杂的道路场景
  • 【python-docx 07】使用word样式
  • python读取docx文件,就是如此简单
  • Caused by: java.lang.ClassNotFoundException: freemarker.template.Configuration
  • A component required a bean of type ‘XXX‘ that could not be found 解决办法
  • spring aop 自定义注解配合swagger注解保存操作日志到mysql数据库含(源码)
  • 小而美 | Mac上鲜为人知,但极大提升效率的小工具
  • 防火墙体系结构的组合形式
  • E - B-莲子的机械动力学
  • 需要克服的缺点
  • 高版本springboot整合swagger
  • PHP. 03 .ajax传输XML、 ajax传输json、封装
  • ajax请求php返回xml数据格式,ajax传输的数据格式(XML,json)怎么获取解析
  • JavaScript基础之Ajax总结大全
  • Ajax入门和发送http请求
  • 04-Ajax传输json和XML
  • python网络爬虫——爬虫第三方库的使用(二)
  • ajax使用频率,11-Ajax详解
  • 使用Ajax发送http请求(getpost请求)
  • 人加智能FPGA应用实践-AI快速进化
  • Mac显示证书不受信任或者无效的解决办法
  • Mac | 解决证书不受信任问题
  • Java 解析CA证书 对数据进行签名和验签
  • ca证书 csr_什么是csr证书
  • 招行网银证书不见了
  • 网银的业务学习之道:数字证书的基础知识
  • 网上银行安全证书工作原理
  • 数字证书基础
  • 网上银行数字证书原理
  • 海南农信服务器证书异常,农商银行网银显示服务器没有收到您的证书怎么办
  • 顺德农商银行服务器没有收到您的证书,农商行网上银行u盘插入,提示没有证书怎么回......