码迷,mamicode.com
首页 > 编程语言 > 详细

c++ primer plus 第三章 课后题答案

时间:2019-01-06 22:02:52      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:day   orm   line   contains   ber   ret   inf   pre   nta   

技术分享图片

#include<iostream>
using namespace std;

int main()
{
    const int unit=12;
    int shen_gao;
    cout <<"Please enter your leight in inches:____\b\b\b";
    cin >> shen_gao;
    cout << "It is contains: " << shen_gao / unit << " feet" << ", " << shen_gao % unit << " inches.";
    cin.get();
    cin.get();

    return 0;
}

 

技术分享图片

#include<iostream>
using namespace std;

const int F_1 = 12;
const double F_2 = 0.0254;
const double F_3 = 2.2;

int main()
{
    int feet;
    int inch;
    double pound;
    double BMI;

    cout << "What‘s your heights?" << endl;
    cout << "Please enter your heights in feet: ";
    cin >> feet;
    cout << "Please enter your heights in inch: ";
    cin >> inch;
    cout << endl << "What‘s your pound?" << endl << "Please enter your pound: ";
    cin >> pound;
    BMI = (pound/F_3)/((inch+feet* F_1)*F_2);
    cout << endl << "Your BMI is " << BMI*BMI << ".";

    cin.get();
    cin.get();
    return 0;
}

 

技术分享图片

#include<iostream>
using namespace std;

const int Du_fen = 60;
const int Fen_miao = 60;

int main()
{
    int degrees;
    int minutes;
    int seconds;

    cout << "Enter a latitude in degrees, minutes, seconds:\n" << "First, enter the degrees: ";
    cin >> degrees;
    cout << "Next, enter the minutes of arc: ";
    cin >> minutes;
    cout << "Finally, enter the seconds of arc: ";
    cin >> seconds;
    cout << degrees << " degrees, " << minutes << " minutes, " << seconds << " seconds = "
        << degrees + double(minutes) / Du_fen + double(seconds) / Fen_miao / Du_fen << " degrees";

    cin.get();
    cin.get();
    return 0;
}

 

 技术分享图片

#include<iostream>
using namespace std;

const int day_hour = 24;
const int hour_min = 60;
const int min_sec = 60;

int main()
{
    int day;
    int hour;
    int min;
    int sec;
    long second;
    cout << "Enter the number of seconds: ";
    cin >> second;

    day = second / min_sec / hour_min / day_hour;
    hour = second / min_sec / hour_min % day_hour;
    min = second / min_sec % hour_min;
    sec = second % min_sec;
    cout << second << " seconds = " << day << " days, " << hour << " hours, " << min << " minutes, " << sec << " seconds.";

    cin.get();
    cin.get();
    return 0;

}

 

 技术分享图片

 

#include<iostream>
using namespace std;

int main()
{
    long long peo_of_wor;
    long long peo_of_con;

    cout << "Enter the world‘s population: ";
    cin >> peo_of_wor;
    cout << "Enter the population of the US:";
    cin >> peo_of_con;
    cout << "The population of the US is " << (double(peo_of_con) / peo_of_wor * 100) << "% of the world population.";

    cin.get();
    cin.get();
    return 0;
}

 

 技术分享图片

#include<iostream>
using namespace std;

int main()
{
    double miles, gallons, kilometers, liter;
    int flage;

    cout << "You have two forms of fuel consumption: " << endl
         << "1- the mile of per gallons" << endl
         << "2- the liter of one hundred kilometer" << endl
         << "Plesase chioce(enter 1 or 2): ";
    cin >> flage;
    if (flage == 1)
    {
        cout << "Please enter the distance(mile): ";
        cin >> miles;
        cout << "Please enter the gasoline amount(gallon): ";
        cin >> gallons;
        cout << "Wasting a gallon gasoline run " << miles / gallons << " miles." << endl;
    }
    else {
        cout << "Please enter the distance(kilometer):";
        cin >> kilometers;
        cout << "Please enter the gasoline amount(liter):";
        cin >> liter;
        cout << "Wasting gasoline per hundred kilometers is " << liter / kilometers * 100 << " liters." << endl;
    }
    cin.get();
    cin.get();
    return 0;
}

 

技术分享图片

#include<iostream>
using namespace std;
const float One_H_Kilometer_mile = 62.14;
const float Gallon_liter = 3.875;

int main()
{
    float european_style;
    float america_style;
    cout << "Please enter European style fuel consumption: ";
    cin >> european_style;
    america_style = One_H_Kilometer_mile * Gallon_liter / european_style;
    cout << european_style << "/100 km = " << america_style << " mpg";
    cin.get();
    cin.get();
    return 0;
}

 

c++ primer plus 第三章 课后题答案

标签:day   orm   line   contains   ber   ret   inf   pre   nta   

原文地址:https://www.cnblogs.com/CJT-blog/p/10230346.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!