课后编程题(第三章)

章节总结

 编程题预览

题目解答

 代码

#include "stdafx.h"
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
    const int convertFactor = 3;
    cout << "请输入距离___\b\b\b" ;
    int height = 0;
    cin >>height ;
    cout << "您的身高为:" << convertFactor*height << "英尺" << endl;
    system("pause");
    return 0;
}

运行结果

请输入距离100

您的身高为:300英尺

请按任意键继续. . .

 

 代码:

#include "stdafx.h"
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
    const int Foot2Inch = 12;//英尺转英寸
    const float Inch2Mi = 0.0254;//英寸转米
    const float Kg2Pount = 2.2;//千克转磅 
    int foot = 0;
    int inch = 0;
    float pount = 0;
    cout << "请输入身高(英尺):";
    cin >> foot;
    cout << endl;
    cout << "请输入身高(英寸):";
    cin >> inch; 
    cout << endl;
    cout << "请输入体重(磅):";
    cin >> pount;
    cout << endl;
    double height = 0;
    double weight = 0;
    height = (foot*Foot2Inch + inch)*Inch2Mi;
    weight = pount / Kg2Pount;
    cout << "你的身高为:" << height << "" << endl;
    cout << "你的体重为:" << weight << "kg" << endl;
    cout << "你的BMI为:" << weight / (height*height) << endl;
    system("pause");
    return 0;
}

运行结果:

请输入身高(英尺):12

请输入身高(英寸):2

请输入体重(磅):199

你的身高为:3.7084

你的体重为:90.4545kg

你的BMI为:6.57745

 请按任意键继续. .

.

  代码:

#include "stdafx.h"
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
    const float degrees2minutes = 60.0;
    const float minutes2seconds = 60.0;
    int degrees, minutes, seconds;
    degrees = 0;
    minutes = 0;
    seconds = 0;
    cout << "Enter a latitude in degrees, minutes, and secondes:" << endl;
    cout << "First, enter the degrees:";
    cin >> degrees;
    cout << "Next, enter the minutes:";
    cin >> minutes;
    cout << "Finally, enter the seconds:";
    cin >> seconds; 
    cout << degrees << "degrees" << minutes << "minutes" << \
        seconds << "seconds" << "=" << (seconds / minutes2seconds + \
        minutes) / degrees2minutes + degrees << "degrees";
    system("pause");
    return 0;
}

运行结果:

Enter a latitude in degrees, minutes, and secondes:

First, enter the degrees:37

Next, enter the minutes:51

Finally, enter the seconds:19

37degrees51minutes19seconds=37.8553degrees请按任意键继续. . .

 代码:

#include "stdafx.h"
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
    const int minute2seconds = 60;
    const int hour2minutes = 60;
    const int day2hours = 24;
    int seconds; 
    seconds = 0;
    cout << "Enter the number of seconds:" << endl;  
    cin >> seconds; 
    cout << seconds << "seconds" << "=" << seconds%minute2seconds << "seconds," \
        << seconds / minute2seconds%hour2minutes << "minutes," \
        << seconds / minute2seconds / hour2minutes%day2hours << "hours,"\
        << seconds / minute2seconds / hour2minutes / day2hours << "days,";

    system("pause");
    return 0;
}

运行结果:

Enter the number of seconds:

31600000

31600000seconds=40seconds,46minutes,17hours,365days,请按任意键继续. . .

 

 代码:

#include "stdafx.h"
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
    const int minute2seconds = 60;
    const int hour2minutes = 60;
    const int day2hours = 24;
    int worldPop = 0;
    int USPop = 0; 
    cout << "Enter the world's population:" ;
    cin >> worldPop;
    cout << "Enter the US's population:" ; 
    cin >> USPop;
    cout << "The population of the US is " << (float)USPop/(float)worldPop<< "of the world population";
    system("pause");
    return 0;
}

运行结果:

Enter the world's population:689878899

Enter the US's population:310783781

The population of the US is 0.45049of the world population请按任意键继续. . .

 代码:

#include "stdafx.h"
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
    float km = 0.0;
    float rise = 0; 
    cout << "输入驱车里程(公里):" ;
    cin >> km; 
    cout << "输入加油量(升):";
    cin >> rise;
    cout << "每100公里耗油量为" << rise / km * 100<<""; 
    system("pause");
    return 0;
}

运行结果:

输入驱车里程(公里):100

输入加油量():323

100公里耗油量为323升请按任意键继续. .

 

 代码:

#include "stdafx.h"
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
    float risePer100km = 0; 
    const float km2mile = 0.6214;
    const float gallon2rise = 3.875;

    cout << "输入每100公里耗油量(升):" ;
    cin >> risePer100km;

    cout << "每加仑奔跑距离:" << 100 / (risePer100km / gallon2rise); 
    system("pause");
    return 0;
}

运行结果:

输入每100公里耗油量():100

每加仑奔跑距离:3.875请按任意键继续. . .

猜你喜欢

转载自www.cnblogs.com/feichangnice/p/11756995.html
今日推荐