c++ primer plus chapter3 习题

在这里插入图片描述

#include<iostream>
using namespace std;

const int FOOT_TO_INCH = 12;

int main() {
	int height;
	cout << "Please enter your height int inches_";
	cin >> height;
	cout << "Your height converts to " << height / FOOT_TO_INCH;
	cout << " food and " << height % FOOT_TO_INCH << " inches." << endl;
	return 0;
}

在这里插入图片描述

#include<iostream>
using namespace std;

const int FOOT_TO_INCH = 12;
const double INCH_TO_METER = 0.0254;
const double KILLOGRAM_TO_POUND = 2.2;

int main() {
	int height_foot, height_inch;
	double weight_pound, height, weight, bmi;
	cout << "Please enter your height foot:";
	cin >> height_foot;
	cout << "Please enter your height inch:";
	cin >> height_inch;
	cout << "Please enter your weight pounds:";
	cin >> weight_pound;
	height = (height_foot * FOOT_TO_INCH + height_inch) * INCH_TO_METER;
	weight = weight_pound / KILLOGRAM_TO_POUND;
	bmi = weight / (height * height);
	cout << "Your BMI is " << bmi << endl;
	return 0;
}

在这里插入图片描述

#include<iostream>
using namespace std;

const int DEGREE_TO_MINUTE = 60;
const int DEGREE_TO_SECOND = 3600;

int main() {
	int degree, minute, second;
	double degree_style;
	cout << "Enter a latitude in degrees, minutes, and seconds:" << endl;
	cout << "First, enter the degrees:";
	cin >> degree;
	cout << "Next, enter the minutes of arc:";
	cin >> minute;
	cout << "Finally, enter the seconds of arc:";
	cin >> second;
	degree_style = degree + (double)minute / DEGREE_TO_MINUTE + (double)second / DEGREE_TO_SECOND;
	cout << degree << " degrees, " << minute << " minutes, " << second << " seconds = " << degree_style << " degrees." << endl;
	return 0;
}

在这里插入图片描述

#include<iostream>
using namespace std;

const int DAY_TO_HOUR = 24;
const int HOUR_TO_MINUTE = 60;
const int MINUTE_TO_SECOND = 60;

int main() {
	long seconds;
	cout << "Enter the number of seconds:";
	cin >> seconds;
	cout << seconds << " seconds = " << seconds / (DAY_TO_HOUR * HOUR_TO_MINUTE * MINUTE_TO_SECOND) << " days,";
	cout << seconds % (DAY_TO_HOUR * HOUR_TO_MINUTE * MINUTE_TO_SECOND) / (MINUTE_TO_SECOND * HOUR_TO_MINUTE) << " hours, ";
	cout << seconds % (DAY_TO_HOUR * HOUR_TO_MINUTE * MINUTE_TO_SECOND) % (MINUTE_TO_SECOND * HOUR_TO_MINUTE) / MINUTE_TO_SECOND << " minutes, ";
	cout << seconds % (DAY_TO_HOUR * HOUR_TO_MINUTE * MINUTE_TO_SECOND) % (MINUTE_TO_SECOND * HOUR_TO_MINUTE) % MINUTE_TO_SECOND << " seconds." << endl;
	return 0;
}

在这里插入图片描述

#include<iostream>
using namespace std;

int main() {
	long long world_population, US_population;
	double percent;
	cout << "Enter the world's population: ";
	cin >> world_population;
	cout << "Enter the population of the US: ";
	cin >> US_population;
	percent = (double)US_population / world_population * 100;
	cout << "The population of the US is " << percent << "% of the world population." << endl;
	return 0;
}

在这里插入图片描述

#include<iostream>
using namespace std;

int main() {
	double distance_in_miles, fuel_in_gallon;
	double distance_in_kilometer, fuel_in_litre;
	double fuel_consume;
	cout << "Enter the distance in miles: ";
	cin >> distance_in_miles;
	cout << "Enter the fuel consume in gallon: ";
	cin >> fuel_in_gallon;
	fuel_consume = distance_in_miles / fuel_in_gallon;
	cout << "The fuel consume is " << fuel_consume << " miles/gallon." << endl;
	cout << "Enter the distance in kilometer: ";
	cin >> distance_in_kilometer;
	cout << "Enter the fuel consume in litre: ";
	cin >> fuel_in_litre;
	fuel_consume = fuel_in_litre / (distance_in_kilometer*100);
	cout << "The fuel consume is " << fuel_consume << " L/100km." << endl;
	return 0;
}

在这里插入图片描述

#include<iostream>
using namespace std;

const double GALLON_TO_LITRE = 3.875;
const double HKM_TO_MILE = 62.14;

int main() {
	double fuel_consume_eur, fuel_consume_us;
	cout << "Enter the fuel consume in europe(L/100Km): ";
	cin >> fuel_consume_eur;
	fuel_consume_us = (GALLON_TO_LITRE * HKM_TO_MILE) / fuel_consume_eur;
	cout << "The fuel consume is " << fuel_consume_us << " miles/gallon." << endl;
	return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

薛定谔的喵~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值