学习笔记——C++ Primer Plus 第六版 第三章编程练习答案

    科技2025-10-27  7

    在这里插入代码片 #include<iostream> using namespace std; const int Inch2Foot = 12; int main() { int height_inch; int heighe_foot; int height_inch_ = 0; cout << "please input your height in inch___\b\b\b:"; cin >> height_inch; heighe_foot = height_inch / 12; height_inch_ = height_inch % 12; cout << "your height in inch was: " << height_inch << " inch" << endl; cout << "your height in foot and inch was: " << heighe_foot << " foot " << height_inch_ << " inch" << endl; system("pause"); return 0; } #include<iostream> using namespace std; int main() { double height_foot, height_inch; double weight_pound; double height_meter; double weight_kg; double BMI; cout << "Please input your height in foot and inch:"; cin >> height_foot; cin >> height_inch; cout << "Please input your weight pound:"; cin >> weight_pound; weight_kg = weight_pound / 2.2; height_meter = (height_foot * 12 + height_inch) * 0.0254; BMI = weight_kg / (height_meter * height_meter); cout << "Your BIM is " << BMI << endl; system("pause"); return 0; } #include<iostream> using namespace std; int main() { double degree, minute, second=0; cout << "Enter a latitude in degrees,minutes,and seconds:" << endl; cout << "First,enter the degree:"; cin >> degree; cout << "Next,enter the minutes of arc:"; cin >> minute; cout << "Finally,enter the seconds of arc:"; cin >> second; double total_degree; total_degree = degree + minute / 60 + second / 60 / 60; cout << degree << " degrees," << minute << " minutes," << second << " seconds = " << total_degree << " degree" << endl; system("pause"); return 0; } #include<iostream> using namespace std; int main() { long long seconds; int tem; int day, hour, minute, second; cout << "Enter the number of seconds:"; cin >> seconds; day = seconds / (24 * 60 * 60); tem = seconds % (24 * 60 * 60); hour = tem / (60*60); tem = tem % (60 * 60); minute = tem / 60; second = tem % 60; cout << seconds << " seconds = " << day << " days," << hour << " hours," <<minute<<" minutes," <<second << " seconds" << endl; system("pause"); return 0; } #include<iostream> using namespace std; int main() { long long popu_world, popu_US; cout << "Enter the world's population:"; cin >> popu_world; cout << "Enter the population of the US:"; cin >> popu_US; double percentage; percentage = double(popu_US) / double(popu_world); cout << "The population of the US is " << percentage * 100 << "% of the world population." << endl; system("pause"); return 0; } #include<iostream> using namespace std; int main() { double mile, gallon; double mile_per_gallon; cout << "Please input mileage(mile):"; cin >> mile; cout << "Please input comsumption of oil(gallon):"; cin >> gallon; mile_per_gallon = mile / gallon; cout << "The distance per gallon is " << mile_per_gallon << " mile." << endl; double km, litre; double litre_per_100km; cout << "Please input mileage(km):"; cin >> km; cout << "Please input comsumption of oil(litre):"; cin >> litre; litre_per_100km = 100 * litre / km; cout << "The comsumption of oil per 100km is " << litre_per_100km << " litre" << endl; system("pause"); return 0; } #include<iostream> using namespace std; int main() { double fuel_comsuption_eu = 0.0; double fuel_comsuption_us = 0.0; printf("Please input fuel comsuption in Europ standard:"); cin >> fuel_comsuption_eu; fuel_comsuption_us = 62.14 * 3.785 / fuel_comsuption_eu; cout << "the fuel comsuption in US standard is " << fuel_comsuption_us << "mile/gallon" << endl; system("pause"); return 0; }
    Processed: 0.010, SQL: 8