3.7.1modulusHeight
#include <iostream>
int main()
{
using namespace std;
const int trans_factor = 12;
cout << "Please enter you height for inch:"___\b\b\b;
int height_inch;
cin >> height_inch;
cout << "You height is " << height_inch / trans_factor << " foot "
<< height_inch % trans_factor << " inch.";
return 0;
}
3.7.2BMI
#include <iostream>
int main()
{
using namespace std;
int inch_height, foot_height, pounfs_weight;
const double trans_weight = 2.2;
const double trans_inch_to_meter = 0.0254;
const double trans_foot_to_inch = 12;
cout << "Please enter you height and weight: " << endl;
cout << "___foot\b\b\b\b\b\b";
cin >> foot_height;
cout << "___inch\b\b\b\b\b\b";
cin >> inch_height;
cout << "_____pounds\b\b\b\b\b\b\b\b\b\b";
cin >> pounfs_weight;
double weight_kg = pounfs_weight / trans_weight;
double height_m = (foot_height * trans_foot_to_inch + inch_height) * trans_inch_to_meter;
cout << "Your BMI is " << weight_kg / height_m / height_m << ".";
return 0;
}
3.7.3 latitude
#include <iostream>
#include <cmath>
int main()
{
using namespace std;
const double trans_factor = 60.0;
int degrees, minutes, seconds;
cout << "Enter a latitude in degrees, minutes, and seconds; " << endl;
cout << "Frist, enter the degrees: ";
cin >> degrees;
cout << "Next, enter the minutesof arc: ";
cin >> minutes;
cout << "Finally, enter the seconds of arc: ";
cin >> seconds;
cout << degrees << " degrees, " << minutes << " minutes, " << seconds << " seconds = "
<< degrees + minutes / trans_factor + seconds / pow(trans_factor, 2) << " degrees.";
return 0;
}
3.7.4time_trans
#include <iostream>
int main()
{
using namespace std;
long seconds;
cin >> seconds;
const int seconds_of_one_day = 24*60*60;
const int seconds_of_one_hour = 3600;
const int seconds_of_one_minute = 60;
int days = seconds / seconds_of_one_day;
int temp = 0;
temp = seconds % seconds_of_one_day;
int hours = temp / seconds_of_one_hour;
temp= temp % seconds_of_one_hour;
int minutes = temp / seconds_of_one_minute;
temp= temp % seconds_of_one_minute;
cout << seconds << "seconds = "<< days<<" days,"<<hours<<" hours,"<< minutes <<" minutes," << temp << " seconds";
return 0;
}
3.4.5percntage_of_the_US_population
#include <iostream>
int main()
{
using namespace std;
long long population_US, population_world;
cout << "Enter the world's population: ";
cin >> population_world;
cout << "Enter the population of the US: ";
cin >> population_US;
double percntage = population_US * 100.0 / population_world;
cout << "The population of the US is " << percntage << "\% of the world population.";
return 0;
}
3.7.7oil_consumption
// 1英里(MI)= 1.609344公里(km)
// 1加仑(gal) = 3.7854升
#include <iostream>
#include <cmath>
int main()
{
using namespace std;
const double mi_to_100km = 0.01609344;
const double gal_to_L = 3.7854;
double oil_consumption_Eru, oil_consumption_US;
cout << "Enter the oil cusumption in US style: ";
cin >> oil_consumption_US;
cout << "The oil cusumption in Eru is: " << gal_to_L / mi_to_100km / oil_consumption_US;
return 0;
}