学习笔记——C++ Primer Plus 第六版 第三章编程练习答案

在这里插入代码片
#include<iostream>
using namespace std;
const int Inch2Foot = 12;
int main()
{
    int height_inch;
    int heighe_foot;
    int height_inch_ = 0;
    
    cout << "please input your height in inch___\b\b\b:";
    cin >> height_inch;
    heighe_foot = height_inch / 12;
    height_inch_ = height_inch % 12;
    cout << "your height in inch was: " << height_inch << " inch" << endl;
    cout << "your height in foot and inch was: " << heighe_foot << " foot " << height_inch_ << " inch" << endl;
    
    system("pause");
    return 0;
}
#include<iostream>
using namespace std;
int main()
{
    double height_foot, height_inch;
    double weight_pound;
    double height_meter;
    double weight_kg;
    double BMI;
    
    cout << "Please input your height in foot and inch:";
    cin >> height_foot;
    cin >> height_inch;
    cout << "Please input your weight pound:";
    cin >> weight_pound;
    
    weight_kg = weight_pound / 2.2;
    height_meter = (height_foot * 12 + height_inch) * 0.0254;
    BMI = weight_kg / (height_meter * height_meter);
    
    cout << "Your BIM is " << BMI << endl;
    
    system("pause");
    return 0;
}
#include<iostream>
using namespace std;
int main() 
{
 double degree, minute, second=0;
 cout << "Enter a latitude in degrees,minutes,and seconds:" << endl;
 cout << "First,enter the degree:";
 cin >> degree;
 cout << "Next,enter the minutes of arc:";
 cin >> minute;
 cout << "Finally,enter the seconds of arc:";
 cin >> second;
 double total_degree;
 total_degree = degree + minute / 60 + second / 60 / 60;
 cout << degree << " degrees," << minute << " minutes," 
  << second << " seconds = " << total_degree << " degree" << endl;
 system("pause");
 return 0;
}
#include<iostream>
using namespace std;
int main()
{
 long long seconds;
 int tem;
 int day, hour, minute, second;
 cout << "Enter the number of seconds:";
 cin >> seconds;
 day = seconds / (24 * 60 * 60);
 tem = seconds % (24 * 60 * 60);
 hour = tem / (60*60);
 tem = tem % (60 * 60);
 minute = tem / 60;
 second = tem % 60;
 cout << seconds << " seconds = " << day << " days," << hour 
  << " hours," <<minute<<" minutes," <<second << " seconds" << endl;
 system("pause");
 return 0;
}
#include<iostream>
using namespace std;
int main()
{
 long long popu_world, popu_US;
 cout << "Enter the world's population:";
 cin >> popu_world;
 cout << "Enter the population of the US:";
 cin >> popu_US;
 double percentage;
 percentage = double(popu_US) / double(popu_world);
 cout << "The population of the US is " << percentage * 100 << "% of the world population." << endl;
 system("pause");
 return 0;
}
#include<iostream>
using namespace std;
int main()
{
 double mile, gallon;
 double mile_per_gallon;
 cout << "Please input mileage(mile):";
 cin >> mile;
 cout << "Please input comsumption of oil(gallon):";
 cin >> gallon;
 mile_per_gallon = mile / gallon;
 cout << "The distance per gallon is " << mile_per_gallon << " mile." << endl;
 
 double km, litre;
 double litre_per_100km;
 cout << "Please input mileage(km):";
 cin >> km;
 cout << "Please input comsumption of oil(litre):";
 cin >> litre;
 litre_per_100km = 100 * litre / km;
 cout << "The comsumption of oil per 100km is " << litre_per_100km << " litre" << endl;
 
 system("pause");
 return 0;
}
#include<iostream>
using namespace std;
int main()
{
 double fuel_comsuption_eu = 0.0;
 double fuel_comsuption_us = 0.0;
 printf("Please input fuel comsuption in Europ standard:");
 cin >> fuel_comsuption_eu;
 fuel_comsuption_us = 62.14 * 3.785 / fuel_comsuption_eu;
 cout << "the fuel comsuption in US standard is " << fuel_comsuption_us << "mile/gallon" << endl;
 system("pause");
 return 0;
}
  • 6
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值