//编程练习3.7
#include <iostream>
using namespace std;
int main1()
{
const int Convert = 12;//1 feet=12 inches
cout << "please input your height in inches: ________\b\b\b\b\b\b\b\b";
int inches;
cin >> inches;
int height_feet = inches / Convert;
int height_inches = inches % Convert;
cout << " your height is: " << height_feet << " feet and " << height_inches << " inches. " << endl;
return 0;
}
int main2()
{
const double Feet2Inch = 12;
const double Inch2Meter = 0.254;
const double Kilo2Pound = 2.2;
cout << " Please input your height in feet and inches! \n";
cout << " The feet is: ";
double height_feet = 0.0;
cin >> height_feet;
cout << " The inches is: ";
double height_inch = 0.0;
cin >> height_inch;
cout << " Your weight in pound is: ";
double weight_pound = 0.0;
cin >> weight_pound;
double height_meter = (height_feet*Feet2Inch + height_inch)*Inch2Meter;
double weight_kg = weight_pound / Kilo2Pound;
double BMI = weight_kg / (height_meter*height_meter);
cout << " Your BMI is: " << BMI << endl;
return 0;
}
int main3()
{
const int Convert = 60;
cout << "Enter a latitude in degrees, minute and seconds:" << endl;
cout << "First, enter the degrees: ";
double degrees = 0;
cin >> degrees;
cout << "Next, enter the minucts of arc: ";
double minutes = 0;
cin >> minutes;
cout << "Finally, enter the seconds of arc: ";
double seconds = 0;
cin >> seconds;
cout << seconds / (Convert*Convert) << endl;
double total = degrees+ seconds / (Convert*Convert) + minutes / Convert;
cout << degrees << " degrees, " << minutes << " minutes, " << seconds << " seconds = " << total << " degrees." << endl;
return 0;
}
int main4()
{
const int D2H = 24;
const int H2M = 60;
const int M2S = 60;
cout << "Enter the number of seconds: ";
long long total_seconds = 0;
cin >> total_seconds;
int days = total_seconds / (D2H * H2M * M2S);
int hours = ((total_seconds % (24 * 60 * 60)) / (60 * 60));
int minutes = ((total_seconds % (60 * 60)) / 60);
int seconds = (total_seconds % 60);
cout << total_seconds << " seconds = " << days << " days, " << hours << " hours, " << minutes << " minutes, " << seconds << " seconds" << endl;
return 0;
}
int main5()
{
cout << "Enter the world's population :";
long long world_population = 0;
cin >> world_population;
cout << "Enter the population of the US: ";
long long US_population = 0;
cin >> US_population;
double rate = double(US_population) / (world_population);
cout << "The population of the US is " << rate * 100 << "% of the world population." << endl;
return 0;
}
int main6()
{
//英里/加仑
cout << "Enter the distance in mile: ";
double miles;
cin >> miles;
cout << "Enter the petrol: ";
double gallon;
cin >> gallon;
cout << "Average fuel comsuption: " << miles / gallon << " mile/gallon" << endl;
//欧洲风格
cout << "Enter the distance in Km: ";
double Km;
cin >> Km;
cout << "Enter the petrol: ";
double L;
cin >> L;
cout << "Average fuel comsuption: " << L/Km*100 << " L /100Km" << endl;
return 0;
}
int main7()
{
cout << "Enter the fuel comsuption in Europ standard: ";
double E;
cin >> E;
double US = E / 12.41 * 19;
cout << "The fuel comsuption in US standard is " << US << " mpg. " << endl;
return 0;
}
C++ Primer Plus 编程练习3.7
最新推荐文章于 2022-07-19 13:04:51 发布