#include <iostream>
using namespace std;
int main()
{
//1.编写一个小程序输入身高(英尺)转换为英寸(12英寸等于1英尺)
float height;
const int change=12;
cout<<"请输入你的身高:_____inch\b\b\b\b\b\b\b\b\b";
cin>>height;
cout<<"您的身高是:"<<change*height<<"ft"<<endl;
return 0;
//2.计算BMI,输入身高(英寸),体重(磅)(1英寸=0.0254m,1kg=2.2pound)
float height,weight,BIM;
const float ft2m=0.0254;
const float pound2k=1.0/2.2;
cout<<"请输入你的身高:_____ft\b\b\b\b\b\b\b\b\b";
cin>>height;
height=height*ft2m;
cout<<"请输入你的体重:_____weight\b\b\b\b\b\b\b\b\b";
cin>>weight;
weight=pound2k*weight;
cout<<"您的BIM指数是:"<<weight/height*height;
//3.维度,度分秒转换
int degree,minute,second;
cout<<"Enter a latitude in degrees,minutes,and seconds "<<endl;
cout<<"First,enter the degrees: ";
cin>>degree;
cout<<"Next,enter the minutes of arc: ";
cin>>minute;
cout<<"Finally ,enter the seconds of arc: ";
cin>>second;
cout<<degree<<"degree, "<<minute<<"minutes"<<second<<"second ="<<degree+(float)minute/60.0+(float)second/60.0/60.0<<"degrees";
//4.用户以秒数输入,然后用日,分秒表示这段时间
long time;
int day,minutes,seconds;
cout<<"Enter the number of seconds: "<<endl;
cin>>time;
day=time/(60*60*24);
minutes=(time-day*(60*60*24))/60;
seconds=time-day*(60*60*24)-minutes*60;
cout<<time<<"seconds = "<<day<<"day,"<<minutes<<"minutes,"<<seconds<<"seconds"<<endl;
//5.输入公里数与油耗,求出没百公里耗油量。
float distance,liter;
cout<<"请输入公里数:";
cin>>distance;
cout<<"请输入升数:";
cin>>liter;
cout<<"每百公里油耗:"<<100*(liter/distance);
//6.输入欧洲风格耗油量(100km耗多少升)转换为美国风格油耗量(距离(英里)/燃料(加仑)mpg)
float EurpStyle,USAStyle;
cout<<"请输入欧洲风格油耗量(L/100km): ";
cin>>EurpStyle;
USAStyle=1/((0.264/0.621)*EurpStyle/100);
cout<<"等于: "<<USAStyle<<"mpg";
}
C++ Primer Plus 学习日志*第三章课后编程练习题
最新推荐文章于 2024-05-14 15:27:08 发布