《C++ Primer Plus》第三章 处理数据 ——Part 3

课后编程练习

#include <iostream>
using namespace std;
const int POW = 12;

int main()
{
	int Inch;
	cout << "Put in your height in inch:___\b\b\b";
	cin >> Inch;
	cout << "Your height is " << Inch / POW << " feet and " << Inch % POW << " inches.\n";
	return 0;
}

#include <iostream>
using namespace std;

int feet, inches;
double pounds;
double weight_in_kg;
double height_in_m;
int height_in_inches;

const int FEET_TO_INCHES = 12;
const double INCHES_TO_M = 0.0254;
const double POUNDS_TO_KG = 2.2;

int main()
{
	cout << "Putin your height (xx feet and xx inches): \n";
	cout << "Feet: ";
	cin >> feet;
	cout << "Inches: ";
	cin >> inches;
	cout << "Putin your weight (xx pounds): ";
	cin >> pounds;
	//Putin
	height_in_inches = inches + feet * FEET_TO_INCHES;
	height_in_m = INCHES_TO_M * double(height_in_inches);
	weight_in_kg = pounds / POUNDS_TO_KG;
	//Change
	cout << "Your height is " << height_in_inches << " inches.\n";
	cout << "Your weight is " << weight_in_kg << " kg.\n";
	cout << "Your BMI is " << weight_in_kg / (height_in_m * height_in_m) << endl;
	//Print out
	return 0;
}

#include <iostream>
using namespace std;

const int DEGREE_TO_MIN = 60;
const int DEGREE_TO_SEC = 3600;

int du, fen, miao;
double degree;

int main()
{
	cout << "Enter a latitude in degrees, minutes, and seconds:\n";
	cout << "First, enter the degrees: ";
	cin >> du;
	cout << "Next, enter the minutes of arc: ";
	cin >> fen;
	cout << "Finally, enter the seconds of arc: ";
	cin >> miao;
	degree = double(du) + double(fen) / DEGREE_TO_MIN + double(miao) / DEGREE_TO_SEC;
	cout << du << " degrees, " << fen << " minutes, " << miao << " seconds = "
		<< degree << " degrees\n";
	return 0;
}

#include <iostream>
using namespace std;

const int DAY_TO_HOUR = 24;
const int HOUR_TO_MIN = 60;
const int MIN_TO_SEC = 60;

long long m;
long long days, hours, minutes, seconds;

int main()
{
	cout << "Enter the number of seconds: ";
	cin >> m;
	long long temp = m;

	days = temp / (DAY_TO_HOUR * HOUR_TO_MIN * MIN_TO_SEC);
	temp %= DAY_TO_HOUR * HOUR_TO_MIN * MIN_TO_SEC;

	hours = temp / (HOUR_TO_MIN * MIN_TO_SEC);
	temp %= HOUR_TO_MIN * MIN_TO_SEC;

	minutes = temp / (MIN_TO_SEC);

	seconds = (temp % MIN_TO_SEC);

	cout << long long(m) << " seconds = "
		<< days << " days, " << hours << " hours, "
		<< minutes << " minutes, " << seconds << " seconds\n";
	return 0;
}

#include <iostream>
using namespace std;

long long sum_people;
long long china_people;
double percentages;

int main()
{
	cout << "Enter the world's population: ";
	cin >> sum_people;
	cout << "Enter the population of China: ";
	cin >> china_people;
	percentages = double(china_people) / double(sum_people) * 100.0;
	cout << "The population of China is " << percentages 
		<< "% of the world population.\n";
	return 0;
}

#include <iostream>
using namespace std;

double km, liter;

int main()
{
	cout << "Enter driving mileage in kilometer: ";
	cin >> km;
	cout << "Input fuel consumption in liter: ";
	cin >> liter;
	cout << "You will comsumer " << liter / km * 100.0
		<< " liters of oil for every 100 kilometers.\n";
	return 0;
}

#include <iostream>
using namespace std;

double liters_every_100km, miles_per_gallon;

const double A_HUNDRED_KM_TO_MILES = 62.14;
const double GALLONS_TO_LITERS = 3.875;

int main()
{
	cout << "Enter fuel consumption in European grid (petrol consumption per 100km(litres)): ";
	cin >> liters_every_100km;
	miles_per_gallon = A_HUNDRED_KM_TO_MILES / (liters_every_100km / GALLONS_TO_LITERS);
	cout << "The American-style fuel consumption is: " << miles_per_gallon << " mpg.\n";
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值