//change.cpp--3.7.1
#include<iostream>
int main(void)
{
using namespace std;
const int FOOT = 12;//英尺和英寸的比例
int tall = 0;
int foot = 0;
int inch = 0;
cout << "Please enter your inch tall:";
cin >> tall;
foot = tall / FOOT;
inch = tall % FOOT;
cout << "Your tall is " << foot
<< " and " << inch << "." << endl;
return 0;
}
//BMI_count.cpp--3.7.2
#include<iostream>
const int FOOT = 12;//1 foot = 12 inch
const float METER = 0.0254f;// 1 inch = 0.0254meter
const float KG = 2.2f;// 1 kg = 2.2 pound
int main(void)
{
using namespace std;
float pound = 0;
float meter = 0;
float kg = 0;
float foot = 0;
float inch = 0;
float bmi = 0;
//get data
cout << "Please enter your height"
<< "in foot and inch" << endl;
cout << "First, enter the foot: ";
cin >> foot;
cout << "Next, input inch: ";
cin >> inch;
cout << "Now,please enter your pound: ";
cin >> pound;
//count
meter = (foot * FOOT + inch)*METER;
kg = pound * KG;
bmi = kg / (meter*meter);
//show
cout << "Your BMI is " << bmi << endl;
return 0;
}
//latitude.c //3.73
#include<iostream>
const int CONSTANT = { 60 };//1 degree = 60 miniute, 1 minute = second
int main(void)
{
using namespace std;
int degrees = { 0 };
int miniutes = { 0 };
int seconds = { 0 };
float sum_degrees = { 0 };
//get data
cout << "Enter a latitude in degrees,"
"minutes ,and seconds:" << endl;
cout << "First, enter the degrees: ";
cin >> degrees;
cout << "Next, enter the miniutes: ";
cin >> miniutes;
cout << "Finally, enter the second: ";
cin >> seconds;
//count
sum_degrees = float(degrees) + float(miniutes) /
CONSTANT + float(seconds) / (CONSTANT*CONSTANT);
//show
cout << degrees << " degrees, " << miniutes << " miniutes, "
<< seconds << " seconds = " << sum_degrees << " degrees";
return 0;
}
//count_time.cpp
#include<iostream>
const int DAY_CONSTANT = { 24 };//1 day =12 hour
const int TIME_CONSTANT = { 60 };
//1 hour = 60 miniutes,1 miniutes = 60 second
int main(void)
{
using namespace std;
long sum_seconds = { 0 };
int seconds = { 0 };
int days = { 0 };
int hours = { 0 };
int miniutes = { 0 };
//get data
cout << "Enter the number of seconds: ";
cin >> sum_seconds;
//count
seconds = (int)sum_seconds%TIME_CONSTANT;
miniutes = ((int)sum_seconds / TIME_CONSTANT) % TIME_CONSTANT;
hours = ((int)sum_seconds / TIME_CONSTANT / TIME_CONSTANT % TIME_CONSTANT);
days = (int)sum_seconds / (DAY_CONSTANT*TIME_CONSTANT*
TIME_CONSTANT);
//show
cout << sum_seconds << " seconds = " << days << " days, "
<< hours << " hours, " << miniutes << " miniutes, "
<< seconds << " seconds " << endl;
cin.get();
cin.get();
return 0;
}
//population_statistics.cpp--3.7.5
#include<iostream>
int main(void)
{
using namespace std;
long long us_population = { 0 };
long long world_population = { 0 };
double us_world_percent = { 0 };
//get population
cout << "Enter the world's population: ";
cin >> world_population;
cout << "Enter the population of us: ";
cin >> us_population;
//count
us_world_percent = double(us_population)
/ double(world_population) * 100;
//show
cout << "The population of the us is " <<
us_world_percent << "% of the world population.";
return 0;
}
//mile_per_gallon.cpp--3.7.6
#include<iostream>
int main(void)
{
using namespace std;
int gallon(0);
int mile(0);
double mile_per_gallon(0);
//get data
cout << "Please enter driving mileage: ";
cin >> mile;
cout << "Now,enter use of gallon: ";
cin >> gallon;
//count
mile_per_gallon = (double)mile / gallon;
//show
cout << "Fuel consumption is "
<< mile_per_gallon << "mpg";
return 0;
}
//mile_per_gallon.cpp--3.7.6
#include<iostream>
const double KILOMETER = 62.14;//100 kilometer = 62.14 mile
const double GALLON = 3.875;//1 gallon = 3.875 litre;
int main(void)
{
using namespace std;
double litre_per_kilometer(0);//european calculation method L/100Km
double mile_per_gallon(0);//us calculation method mpg
//get data
cout << "Please enter gallon usage per 100 kilometer: ";
cin >> litre_per_kilometer;
//count
mile_per_gallon = KILOMETER * GALLON / litre_per_kilometer;
//show
cout << litre_per_kilometer << "/100km ="
<< mile_per_gallon << " mpg ";
return 0;
}