C++ Primer Plus 学习日志*第三章课后编程练习题

#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";

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值