测试时分开测试
#include <iostream>
int main() {
/*
//1
const double InchesToFeet = 12.0; // 转换因子:1英尺 = 12英寸
int height_inches;
std::cout << "请输入身高(单位为英寸):___\b\b\b";
std::cin >> height_inches;
int feet = height_inches / InchesToFeet; // 计算英尺部分
int inches = height_inches % static_cast<int>(InchesToFeet); // 计算英寸部分
std::cout << "身高是:" << feet << "英尺 " << inches << "英寸" << std::endl;
//2
const double InchesToMeters = 0.0254; // 身高转换因子:1英寸 = 0.0254米
const double PoundsToKilograms = 1 / 2.2; // 体重转换因子:1磅 = 1/2.2千克
int feet2, inches2, pounds;
std::cout << "请输入身高:";
std::cin >> feet2 >> inches2;
std::cout << "请输入体重(磅):";
std::cin >> pounds;
int total_inches = feet2 * 12 + inches2; // 计算总英寸
double height_meters = total_inches * InchesToMeters; // 转换身高为米
double weight_kilograms = pounds * PoundsToKilograms; // 转换体重为千克
double bmi = weight_kilograms / (height_meters * height_meters); // 计算BMI
std::cout << "BMI为:" << bmi << std::endl;
//3
const int MinutesPerDegree = 60; // 1度 = 60分
const int SecondsPerMinute = 60; // 1分 = 60秒
int degrees, minutes, seconds;
std::cout << "请输入纬度的度数:";
std::cin >> degrees;
std::cout << "请输入纬度的分数:";
std::cin >> minutes;
std::cout << "请输入纬度的秒数:";
std::cin >> seconds;
double totalDegrees = degrees + ((double)(minutes) / MinutesPerDegree) +
((double)(seconds) / (MinutesPerDegree * SecondsPerMinute));
std::cout << "纬度为:" << totalDegrees << " 度" << std::endl;
//4
const long long SecondsPerMinute = 60; // 每分钟有多少秒
const long long MinutesPerHour = 60; // 每小时有多少分钟
const long long HoursPerDay = 24; // 每天有多少小时
long long total_seconds;
std::cout << "请输入秒数:";
std::cin >> total_seconds;
long long days = total_seconds / (SecondsPerMinute * MinutesPerHour * HoursPerDay); // 计算天数
long long remaining_seconds = total_seconds % (SecondsPerMinute * MinutesPerHour * HoursPerDay); // 剩余秒数
long long hours = remaining_seconds / (SecondsPerMinute * MinutesPerHour); // 计算小时数
remaining_seconds %= (SecondsPerMinute * MinutesPerHour); // 剩余秒数
long long minutes = remaining_seconds / SecondsPerMinute; // 计算分钟数
remaining_seconds %= SecondsPerMinute; // 剩余秒数
std::cout << total_seconds << " seconds = " << days << " days, " << hours << " hours, " << minutes << " minutes, " << remaining_seconds << " seconds" << std::endl;
//5
long long global_population, country_population;
std::cout << "请输入全球当前的人口:";
std::cin >> global_population;
std::cout << "请输入美国(或其他国家)当前的人口:";
std::cin >> country_population;
double percentage = (double)(country_population) / (double)global_population * 100;
std::cout << "美国(或其他国家)人口占全球人口的百分比为:" << percentage << "%" << std::endl;
//6
const double MilesToKilometers = 1.60934; // 英里到公里的转换因子
const double GallonsToLiters = 3.78541; // 加仑到升的转换因子
double miles, gallons;
std::cout << "请输入驱车里程(英里):";
std::cin >> miles;
std::cout << "请输入使用汽油量(加仑):";
std::cin >> gallons;
double miles_per_gallon = miles / gallons;
std::cout << "汽车每加仑的里程为:" << miles_per_gallon << " 英里/加仑" << std::endl;
double kilometers = miles * MilesToKilometers;
double liters = gallons * GallonsToLiters;
double liters_per_100_km = liters / (kilometers / 100);
std::cout << "欧洲风格下每100公里的耗油量为:" << liters_per_100_km << " 升/100公里" << std::endl;
*/
//7
const double KilometersToMiles = 0.6214; // 公里到英里的转换因子
const double LitersToGallons = 0.2642; // 升到加仑的转换因子
double liters_per_100_km;
std::cout << "请输入汽车的耗油量(每100公里消耗的汽油量,单位:升):";
std::cin >> liters_per_100_km;
double gallons_per_100_mi = liters_per_100_km / LitersToGallons;
double miles_per_gallon = 100 / gallons_per_100_mi * KilometersToMiles;
std::cout << "美国风格下每加仑的里程为:" << miles_per_gallon << " 英里/加仑" << std::endl;
return 0;
}