C++ Primer Plus 编程练习 第三章
来源:互联网 发布:美国 博士 知乎 编辑:程序博客网 时间:2024/06/05 20:33
1编写一个小程序,要求用户输入自己的身高(单位为英寸),然后将身高转换为英尺。使用const符号常量表示转换因子。
#include <iostream>const int Inch_Per_Foot=12;int main(){using namespace std;double h;cout<<"Please enter your high:______\b\b\b\b\b\b";cin>>h;cout<<h/Inch_Per_Foot;cin.sync();cin.get();return 0;}
#include <iostream>const double Inch_Per_Foot=12;const double Ko_To_Pan=2.2;const double Inch_To_MI=0.0254;int main(){using namespace std;double inch,foot,weight,m,k;cout<<"Please enter your high(inch):______\b\b\b\b\b\b";cin>>inch;cout<<"Please enter your high(foot):______\b\b\b\b\b\b";cin>>foot;cout<<"Please enter your weight:______\b\b\b\b\b\b";cin>>weight;m=(inch*Inch_Per_Foot+foot)*Inch_To_MI;k=weight/Ko_To_Pan;cout<<"your BMI is "<<k/m/m;cin.sync();cin.get();return 0;}
3编写一个程序,要求用户以度、分、秒的方式输入一个纬度,然后以度为单位表示。
#include <iostream>const double D_To_M=60.0;const double M_To_S=60.0;int main(){using namespace std;double d,m,s,r;cout<<"Enter a latitude in degrees,minutes, and seconds:"<<endl;cout<<"First, enter the degrees:";cin>>d;cout<<"Next, enter the minutes:";cin>>m;cout<<"Finally, enter the seconds:";cin>>s;cout<<d<<" degress, "<<m<<" minutes, "<<s<<" seconds = "<<(d+(m/D_To_M)+(s/M_To_S/D_To_M)) << " degrees";cin.sync();cin.get();return 0;}
4编写一个程序,要求用户以整数秒的形式输入秒数(使用long或long long),然后以小时、分钟和秒的形式输出。
#include <iostream>const long Hour_Per_Day=24;const long Minute_Per_Hour=60;const long Second_Per_Minute=60;int main(){using namespace std;long d,h,m,s,ss,seconds;cout<<"Enter the number of seconds: ";cin>>ss;seconds=ss;s=ss%Second_Per_Minute; // 获得秒钟 ss=ss/Second_Per_Minute;m=ss%Minute_Per_Hour; // 获得分钟 ss=ss/Minute_Per_Hour;h=ss%Hour_Per_Day; // 获得小时 d=ss/Hour_Per_Day; // 获得天数cout<< seconds <<" seconds = "<< d<<" days, "<<h<<" hours, "<<m<<" minutes, "<<s<<" seconds";cin.sync();cin.get();return 0;}
5编写一个程序,要求用户输入全球当前的人口,将这些信息存储在long long变量中,并让程序显示美国的人口占全球人口的百分比
#include <iostream>int main(){using namespace std;long long world,Amer;cout<<"Enter the world's population: ";cin>>world;cout<<"Enter the population of the US: ";cin>>Amer;double rate=(double)Amer/world*100.0;cout << "The population of the US is " << rate<< "% of the world population.";cin.sync();cin.get();return 0;}
6编写一个程序,要求用户输入驱车里程和使用汽油量,然后指出汽车耗油量为一加仑的里程。
#include <iostream>int main(){using namespace std;double inch,gal;cout<<"Please enter the inch: ";cin>>inch;cout<<"Please enter the gallon: ";cin>>gal;cout<<"耗油量为:"<<inch/gal<<" inch/gallon";cin.sync();cin.get();return 0;}
阅读全文
0 0
- 《c primer plus》编程练习回顾-第三章
- C primer plus(第五版)编程练习第三章
- C++Primer Plus 第三章编程练习个人答案
- C Primer Plus 第三章 编程练习 2-7题
- C++ Primer Plus 编程练习 第三章
- C Primer Plus第二章编程练习
- c++primer plus第五章编程练习
- C++primer plus第六章编程练习
- C++primer plus第十七章编程练习
- C primer plus 第三章编程练习(个人练习答案)
- 《C Primer Plus》第三章编程题
- 记录——《C Primer Plus (第五版)》第七章编程练习第三题
- 记录——《C Primer Plus (第五版)》第八章编程练习第三题
- 记录——《C Primer Plus (第五版)》第九章编程练习第三题
- 记录——《C Primer Plus (第五版)》第十章编程练习第三题
- 记录——《C Primer Plus (第五版)》第十一章编程练习第三题
- C++ Primer Plus第六版 第三章 编程练习答案
- c++ primer plus 第六版第三章编程练习答案
- java反射机制初探
- compile spark2.0.0 with maven
- 多线程之futureTask(future,callable)实例,jdbc数据多线程查询
- Your account already has a valid iOS Distribution certificate!问题解决
- elk5.6.0 centos7 及问题
- C++ Primer Plus 编程练习 第三章
- C++ 复习要点
- javascript第六章2
- "ZUMA"(COCI#2009-2010#contest 5)
- link标签的用法及link属性大全
- Python 中 __all__ 的作用
- 安装Webtatic yum源
- 抽奖
- java.net.ProtocolException: Server redirected too many times (20)