[C++ Primer Plus第六版]第3章

1.

#include<iostream>
using namespace std;
const int turn = 12;
int main()
{
	int n = 0;
	cout << "Enter your level(英寸):______\b\b\b\b\b\b";
	cin >> n;
	cout << "your level(英尺) is:" << n/turn << endl;
	return 0;
}

2.

#include<iostream>
using namespace std;
const int inch = 12;
const int meter = 0.0254;
const int pond = 2.2;
int main()
{
	int n = 0;
	int m = 0;
	int p = 0;
	cout << "Enter your level:";
	cin >> n;
	cout << "英尺" ;
	cin >> m;
	cout << "英寸";
	cout << "Enter your weight:";
	cin >> p;
	int q = (m * inch) + n;
	cout << "your level(英寸) is:" << (m * inch) + n << endl;
	cout << "your level(meters) is:" << q * meter << endl;
	cout << "your weight is:" << p * pond << endl;
	cout << "your BMI is:" << (p * pond)/(q * meter * q * meter) << endl;
	return 0;
}

3.

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

4.

#include<iostream>
using namespace std;
const int day = 86400;
const int hour = 3600;
const int min = 60;
int main()
{	
	int total_seconds = 0;
	int seconds = 0;
	int hours = 0;
	int minutes = 0;	
	int days = 0;
	cout << "Enter the number of seconds:";
	cin >> total_seconds;
	days = total_seconds/day;
	hours = (total_seconds - days * day)/hour;
	minutes = (total_seconds - days * day - hours * hour)/min;
	seconds = (total_seconds - days * day - hours * hour - minutes * min);
	cout << total_seconds << " seconds = " << days 
		<< " days, " << hours << " hours, " << minutes 
		<< " minutes, " << seconds << " seconds " << endl;
	return 0;
}

5.

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

	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值