3.7 编程练习

在这里插入图片描述在这里插入图片描述

1.

#include <iostream>

int main()
{
    using namespace std;

    const int CHANGE = 12;

    int h = 0;
    int feet = 0;
    int inch = 0;

    cout << "Please enter your height(Inches):___\b\b\b";
    cin >> h;
    feet = h / CHANGE;
    inch = h % CHANGE;
    cout << "Your height is " << feet << " feet " << inch << " inches."<< endl;

    return 0;
}

在这里插入图片描述

#include <iostream>
#include <cmath>

int main()
{
    using namespace std;

    const int CHANGE_INCH = 12;
    const double CHANGE_M = 0.0254;
    const double CHANGE_P = 2.2;

    int feet = 0;
    int inch = 0;
    double pound = 0;
    double bmi = 0;

    cout << "请以几英尺几英寸的方式输入您的身高。" << endl;
    cout << "请输入英尺的值:";
    cin >> feet;
    cout << "请输入英寸的值:";
    cin >> inch;
    cout << "请输入您的体重(磅):";
    cin >> pound;

    bmi = pound / CHANGE_P / pow((feet * CHANGE_INCH + inch) * CHANGE_M, 2);
    cout << "您的BMI为 " << bmi << endl;

    return 0;
}

在这里插入图片描述

#include <iostream>

int main()
{
    using namespace std;

    const int CHANGE = 60;

    double degree = 0.0;
    double minute = 0.0;
    double second = 0.0;
    double degrees = 0.0;

    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;

    degrees = degree + (minute + second / CHANGE) / CHANGE;
    cout << degree << " degrees, " << minute << " minutes, " << second << " seconds = " << degrees << " degrees" << endl;

    return 0;
}

在这里插入图片描述

#include <iostream>

int main()
{
    using namespace std;

    const int CHANGE_D = 24;
    const int CHANGE_H = 60;
    const int CHANGE_M = 60;

    long seconds = 0;
    int day = 0;
    int hour = 0;
    int minute = 0;
    int second = 0;

    cout << "Enter the number of seconds: ";
    cin >> seconds;
    second = seconds % CHANGE_M;
    minute = seconds / CHANGE_M % CHANGE_H;
    hour = seconds / CHANGE_M / CHANGE_H % CHANGE_D;
    day = seconds / CHANGE_M / CHANGE_H / CHANGE_D;

    cout << seconds << " seconds = " << day << " days, " << hour << " hours, " << minute << " minutes, " << second << " seconds" << endl;

    return 0;
}


在这里插入图片描述

#include <iostream>

int main()
{
    using namespace std;

    double m = 0.0;
    double g = 0.0;
    double km = 0.0;
    double l = 0.0;

    while (true)
    {
        cout << "请输入驱车里程(英里):";
        cin >> m;
        if (m <= 0) break;
        cout << "请输入使用汽油量(加仑):";
        cin >> g;
        if (g <= 0) break;
        cout << "汽车耗油量为一加仑的里程为 " << m / g << " 英里。" << endl;
        break;
    }

    while (true)
    {
        cout << "请输入驱车里程(公里):";
        cin >> km;
        if (km <= 0) break;
        cout << "请输入使用汽油量(升):";
        cin >> l;
        if (l <= 0) break;
        cout << "汽车每100公里的耗油量为 " << l / km * 100 << " 升。" << endl;
        break;
    }

    return 0;
}

在这里插入图片描述

#include <iostream>

int main()
{
    using namespace std;

    double europe = 0.0;
    double us = 0.0;

    cout << "请按欧洲风格输入汽车的耗油量(每100公里消耗的汽油量(升)):";
    cin >> europe;
    us = 62.14 / (europe / 3.875);
    cout << "美国风格的耗油量为:每加仑 " << us << " 英里。" << endl;

    return 0;
}


在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

淘淘图兔兔呀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值