C++primer plus 第三章练习题

#include <iostream>

using namespace std;

int main(){
	int inch;
	double feet;
	const double factor = 0.0833333333333;
	cout<<"请输入身高(英寸)____";
	cin>>inch;

	feet = factor * inch;

	cout<<"身高为"<<feet<<"英尺"<<endl;

	system("pause");
	return 0;
}
#include <iostream>

using namespace std;

int main(){
	//1英尺 = 12英寸
	const double factor_inch = 12;
	const double factor_m = 0.0254;
	const double factor_kg = 2.2;

	double inch;
	double feet;
	double weight;
	double m;
	double BMI;
	double kg;

	cout<<"请以几英尺几英寸的方式输入身高"<<endl;
	cout<<"英尺:";
	cin>>feet;
	cout<<"英寸:";
	cin>>inch;

	cout<<"请以磅为单位输入体重:";
	cin>>weight;

	inch = factor_inch * feet;
	m = inch * factor_m;
	kg = weight / factor_kg;
	
	BMI = kg / (m*m);

	cout<<"你的BMI是:"<<BMI;
	system("pause");
	return 0;
}
#include <iostream>

using namespace std;

int main(){

	
	int degree = 0;
	int minutes = 0;
	int seconds = 0;
	double total;

	cout << "Enter a latitude in degrees,minutes,and secondes:"<<endl;
	cout << "First,enter the degree:";
	cin >> degree;
	cout  << "Next,enter the minutes of arc:";
	cin >> minutes;
	cout << "Finally,enter the seconds of arc:";
	cin >> seconds;

	total = degree + minutes / 60.0 + seconds / 3600.0;

	cout << degree << " degree, " << minutes << " minutes, " << seconds << " seconds = "
		<< total << " degrees";

	
	
	system("pause");
	return 0;
}
#include <iostream>

using namespace std;

int main() {

	long sec;
	int day;
	int hours;
	int min;

	cout << "Enter the number of seconds:";
	cin >> sec;

	day = sec / (60 * 60 * 24);
	hours = (sec - day * (60 * 60 * 24)) / (60 * 60);
	min = (sec - (day * (60 * 60 * 24) + hours * (60 * 60))) / 60;

	int num = sec - day * 3600 * 24 - hours * 3600 - min * 60;

	cout << sec << " seconds = " << day << " days, " << hours << " hours " 
		<< min << " minutes, " << num << " seconds";
	
	
	system("pause");
	return 0;
}
#include <iostream>

using namespace std;

int main() {

	long long world_pop;
	long long us_pop;
	cout << "Enter the world's population:";
	cin >> world_pop;
	cout << "Enter the population of the us:";
	cin >> us_pop;
	//6898758899
	//310783781
	cout << "The population of the US is " << double(us_pop) / double(world_pop)*100 << "% of the world population.";
	
	
	system("pause");
	return 0;
}
#include <iostream>

using namespace std;

int main() {

	double dirve;
	double petrol;

	cout << "请输入驱车里程(英里):";
	cin >> dirve;
	cout << "请输入使用汽油量(加仑):";
	cin >> petrol;

	cout << "汽车1英里耗油" << dirve / petrol << endl;
	system("pause");
	return 0;
}
#include <iostream>

using namespace std;


int main() {

	double gallon;
	double petrol;

	cout << "请输入汽车每一百公里耗油量(升):";
	cin >> petrol;

	gallon = petrol / 19 * 12.41;

	cout << "每加仑"<<gallon<<"英里"<<endl;
	
	system("pause");
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值