C++ Primier Plus 第六版课后题答案第三章

3.7.1

#include <iostream>
// 1英寸=0.0833英尺
int main()
{
	using namespace std;
	const double x = 0.0833;
	cout << "请输入您的身高(英寸):______\b\b\b\b\b\b";
	double height = 0;
	cin >> height;
	cout << "您的身高为 " << x*height << "英尺" << height << "英寸" << endl;
	return 0;
}

3.7.2

#include <iostream>
// 1英尺=12英寸 1英寸=0.0254米 1千克=2.2磅 BMI=体重(千克)/身高(米)的平方
int main()
{
	using namespace std;
	double inch,feet,weight,height;
	const double x = 12;
	const double y = 0.0254;
	const double z = 2.2;
	cout << "请输入您的身高(以x英尺y英寸形式输入):\n";
	cout << "英尺:";
	cin >> feet;
	cout << "英寸:";
	cin >> inch;
	cout << "您的身高为:" << feet << "英尺" << inch << "英寸" << endl;
	cout << "请输入您的体重(磅):";
	cin >> weight;
	height = (feet * 12 + inch) * 0.0254;
	cout << "您的身高为:" << height << "米。\n";
	cout << "您的体重为:" << weight / 2.2 << "千克。\n";
	cout << "您的BMI值为:" << weight / (2.2 * height * height) << endl;
	return 0;
}

3.7.3

#include <iostream>
int main()
{
	using namespace std;
	double degrees,minutes,seconds;
	const double x = 60;
	double latitude;
	cout << "Enter a latitude in degrees,minutes,and seconds:\n";
	cout << "First,enter the degree:";
	cin >> degrees;
	cout << "Next, enter the minutes of arc:";
	cin >> minutes;
	cout << "Finally,enter the seconds of arc:";
	cin >> seconds;
	latitude = degrees + minutes/x + seconds/x;
	cout << degrees << "degrees," << minutes << "minutes," << seconds << "seconds = " <<
		latitude << "degrees";
	return 0;
}

3.7.4

#include <iostream>
int main()
{
	using namespace std;
	int seconds,minutes,hours,days;
	const int x = 60;
	const int y = 3600;
	const int z = 86400;
	long long nseconds;
	cout << "Enter the number of seconds:";
	cin >> nseconds;
	days = nseconds / z;
	hours = (nseconds - days * z) / y;
	minutes = (nseconds - days * z - hours * y) / x;
	seconds = nseconds - days * z - hours * y - minutes * x;
	cout << nseconds << " seconds = " << days << " days, " << hours << " hours, " <<
		minutes << " minutes, " << seconds << " seconds\n";
	return 0;
}

3.7.5

#include <iostream>
int main()
{
	using namespace std;
	long long world_p;
	long long country_p;
	cout << "Enter the world's population:";
	cin >> world_p;
	cout << "Enter the population of the US:";
	cin >> country_p;
	double rate = double(country_p) / double(world_p);
	cout <<"The population of the US is " << rate * 100 << "%" << 
		" of the world population." << endl;
	return 0;
}

3.7.6

#include <iostream>
int main()
{
	using namespace std;
	double mile;
	double gallon;
	cout << "请输入驱车的里程:";
	cin >> mile;
	cout << "请输入使用的汽油量:";
	cin >> gallon;
	double rate = mile / gallon;
	cout << "耗油一加仑行驶里程数:" << rate << "英里\n";
	return 0;
}

3.7.7

#include <iostream>
int main()
{
	using namespace std;
    double eu;  
    cout << "请输入欧洲风格汽车耗油量:";
    cin >> eu;
    double mile = 62.14;
    double gallon = eu / 3.875;
    cout << "美国风格的耗油量:" << mile / gallon << endl;
	return 0;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值