zoukankan      html  css  js  c++  java
  • c++primer 第三章编程练习答案

    3.7.1

    #include<iostream>
    int main() {
        using namespace std;
        const int unit = 12;
        int height,inch,foot;
        cout << "please input your height __ inch";
        cin >> height;
        inch = height % unit;
        foot = height / unit;
        cin.get();
        cout << "your height is " << foot << " foot " << inch << " inch";
        cin.get();
    }

    3.7.2

    #include<iostream>
    int main() {
        using namespace std;
        cout.setf(ios_base::fixed, ios_base::floatfield);
        const double inch_to_meter = 0.0254;
        const double kg_to_lb = 2.2;
        int inch, foot, lb;
        //float height, weight;
        cout << "please input your height!
    ";
        cout << "foot:_";
        cin >> foot;
        cout << "inch:_";
        cin >> inch;
        cout << "please input your weight " << "___ lb";
        cin >> lb;
        cin.get();
        cout << "your height is " << foot * 10 + inch << " inch
    ";
        cout << "your height is " << (foot * 10 + inch)*inch_to_meter << "m
    ";
        cout << "your weight is " << lb / 2.2 << "kg
    ";
        cout << "your BMI is " << pow((lb / 2.2) / ((foot * 10 + inch)*inch_to_meter), 2);
        //cout << pow(2, 3);
        cin.get();
    }

    3.7.3

    #include<iostream>
    int main() {
        using namespace std;
        const int degree_to_minute = 60;
        const int minute_to_second = 60;
        int degree, minute, second;
        double latitude;
        cout << "Enter a latitude in degree,minutes,and seconds:
    ";
        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;
        cin.get();
        latitude = degree + double(minute) / degree_to_minute + double(second) / degree_to_minute / minute_to_second;
        cout << degree << " degrees," << minute << " minutes," << second << " seconds = " << latitude << " degrees";
        cin.get();
    }

    3.7.4

    #include<iostream>
    int main() {
        using namespace std;
        const int days_to_hours = 24;
        const int hours_to_minutes = 60;
        const int mintutes_to_seconds = 60;
        int days, hours, minutes, seconds,init_times;
        cout << "Enter the number of seconds: ";
        cin >> init_times;
        cin.get();
        days = init_times / mintutes_to_seconds / hours_to_minutes / days_to_hours;
        hours = init_times / mintutes_to_seconds / hours_to_minutes % days_to_hours;
        minutes = init_times / mintutes_to_seconds % hours_to_minutes;
        seconds = init_times % mintutes_to_seconds;
        cout << init_times << " seconds = " << days << " days," << hours << " hours," << minutes << " minutes," << seconds << " seconds.";
        cin.get();
    }

    3.7.5

    #include<iostream>
    int main() {
        using namespace std;
        long long world_num;
        long long us_num;
        cout << "Enter the world's population: ";
        cin >> world_num;
        cout << "Enter the population of the US: ";
        cin >> us_num;
        cin.get();
        cout << "The population of the US is " << double(us_num) / double(world_num)*100 << "% of the world population";
        cin.get();
    }
  • 相关阅读:
    第二阶段冲刺第七天
    学习进度表_十五周
    第二阶段冲刺第六天
    第二阶段冲刺第五天
    第二阶段冲刺第四天
    第二阶段冲刺第三天
    Beta阶段项目总结
    Alpha阶段项目总结
    第二次冲刺站立会议10
    第二次冲刺站立会议09
  • 原文地址:https://www.cnblogs.com/zhang293/p/7366518.html
Copyright © 2011-2022 走看看