C++ Primer Plus第三章课后编程答案

1.

#include <iostream>
int main()
{
	using namespace std;
	const int factor = 12;
	int h,feet;
	cout << "height:____\b\b\b";
	cin >> h;
	feet = h / factor;
	h = h%factor;
	cout <<endl<< "ft:" << feet << "\tin:" << h;
	cin.get();
	cin.get();
}

2.

#include <iostream>
int main()
{
	using namespace std;
	const int ftToIn = 12;
	const double inToM = 0.0254;
	const double kgToPn = 2.2;
	int inch,feet;
	double BMI,pound;
	double h,w;
	cout << "inch:____\b\b\b";
	cin >> inch;
	cout << endl << "feet:____\b\b\b";
	cin >> feet;
	cout << endl << "Pound:____\b\b\b";
	cin >> pound;
	inch = feet * 12 + inch;
	h = inch*inToM;
	w = pound / kgToPn;
	BMI = w / (int(h) ^ 2);
	cout << endl << "BMI:" << BMI << "\th:" << h << "m\tw:" << w<<"kg";
	cin.get();
	cin.get();
}

3.

#include <iostream>
int main()
{
	using namespace std;
	const int degToMin = 60;
	const int MinToSec = 60;
	double deg,min,sec,d;
	cout << "Enter a latitude in degrees,minutes, and seconds" << endl << "First, enter the degrees: ";
	cin >> deg;
	cout << "Next, enter the minutes of arc: ";
	cin >> min;
	cout  << "Finally, enter the seconds of arc: ";
	cin >> sec;
	d = deg+min/degToMin+sec/MinToSec/degToMin;
	cout  << deg << " degrees, " << min << " minutes, " << sec << " seconds = " << d << " degrees";
	cin.get();
	cin.get();
	return 0;
}

4.

#include <iostream>
int main()
{
	using namespace std;
	const int dayToH = 24;
	const int hToM = 60;
	const int mToS = 60;
	int day,h,m,sec;
	long s;
	cout << "Enter the number of seconds: " ;
	cin >> s;
	day = s / mToS / hToM / dayToH;
	h = s / mToS / hToM%dayToH;
	m = s / mToS%hToM;
	sec = s%mToS;
	cout << s << " seconds = " << day << " days, " << h << " hours, " << m << " minutes, " << sec << " seconds";
	cin.get();
	cin.get();
	return 0;
}


5.

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







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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值