C++ Primer Plus | chapter 3 课后编程练习

第三章 处理数据

#include<iostream>
using namespace std;
const int To_inch = 12;
int main()
{
    int inch;
    cout << "Please enter your height (inch): ___\b\b\b";
    cin >> inch;
    int feet = inch / To_inch;
    inch %= To_inch;
    cout << "Height: " << feet << " feet " << inch  << " inch" << endl;
    return 0;
}
#include<iostream>
using namespace std;
const double InchToMeter = 0.0254;
const double PoundsToKg = 1/2.2;
int main()
{
    double feet, inch, height, weight;
    cout << "Height: ___ feet ___ inches" << endl;
    cin >> feet;
    cin >> inch;
    cout << "Weight: ___ pounds" << endl;
    cin >> weight;
    inch += feet*12;
    height = inch * InchToMeter;
    weight *= PoundsToKg;
    cout << "BMI = " << weight / (height*height) << endl;
    return 0;
}
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    double result;
    int deg, minutes, sec;
    cout << "Enter a latitude in degrees, minutes and seconds:" << endl;
    cout << "First, enter the degrees: __\b\b";
    cin >> deg;
    cout << "Next, enter the minutes of arc: __\b\b";
    cin >> minutes;
    cout << "Finally, enter the seconds of arc: __\b\b";
    cin >> sec;
    result = deg*3600 + minutes*60 + sec;
    result /= 3600;
    printf("%d degrees, %d minutes, %d seconds = %.4lf degrees\n", deg, minutes, sec, result);
    return 0;
}
#include<iostream>
#include<cstdio>
using namespace std;
const int HrsPerDay = 24;
const int MinsPerHr = 60;
const int SecsPerMin = 60;
int main()
{
    long long secs, seconds, days;
    int hrs, mints;
    cout << "Enter the number of seconds: ";
    cin >> secs;
    seconds = secs;
    days = secs/(SecsPerMin * MinsPerHr * HrsPerDay);
    secs %= SecsPerMin * MinsPerHr * HrsPerDay;
    hrs = secs/(SecsPerMin * MinsPerHr);
    secs %= SecsPerMin * MinsPerHr;
    mints = secs / SecsPerMin;
    secs %= SecsPerMin;
    printf("%lld seconds = %lld days, %d hours, %d minutes, %lld secs", seconds, days, hrs, mints, secs);
    return 0;
}
#include<iostream>
using namespace std;
int main()
{
    long long popult, pop_US;
    cout << "The world's population: ";
    cin >> popult;
    cout << "The population of US: ";
    cin >> pop_US;
    cout << pop_US*100 /(double)popult << "%" <<endl;
    return 0;
}

#include<iostream>
using namespace std;
int main()
{
    double miles, gallon, km, liter;
    cout << "Enter the distance (miles): ";
    cin >> miles;
    cout << "Enter the gasoline usage (gallon): ";
    cin >> gallon;
    cout << miles / gallon << " mile(s)/gallon" << endl;
    cout << "Enter the distance (kilometers): ";
    cin >> km;
    cout << "Enter the gasoline usage (liters): ";
    cin >> liter;
    cout << liter*100 / km << " liter(s)/100km" << endl;
    return 0;
}
#include<iostream>
using namespace std;
const double KMtoMiles = 62.14;
const double GaltoLiter = 3.875;
int main()
{
    double usage_EU;
    cout << "Enter in the European Style: ";
    cin >> usage_EU;
    cout << 1 / (usage_EU / (GaltoLiter*KMtoMiles)) << "mpg" << endl;   //此处书上应该打错了,应该是27mpg大约合8.71/100km
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值