/*第一题*/
#include<iostream>
using namespace std;
int main()
{
cout<<"Please enter your height ____(英寸)";
//注:1英寸=2.5400厘米,1英尺=12英寸。
//英尺 feet 英寸inches
int heightInches;
cin>>heightInches;
int heightFeet;
heightFeet = heightInches / InchesConverseToFeet;
heightInches = heightInches % InchesConverseToFeet;
cout<<"Your height is "<<heightFeet<<" feet "<<heightInches<<" inches"<<endl;
return 0;
}
/*
第二题:计算BMI(Body Mass Index,体重指数)
*/
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
const int FeetConverseToInches = 12;
const double InchesConverseToMeters = 0.0254;
const double poundConverseToKilogram = 2.2;
cout<<"Please enter your height ____feet____inches(separated by a blank space)";
int heightFeet,heightInches,pound;
cin>>heightFeet>>heightInches;
int height = heightFeet * FeetConverseToInches + heightInches;
cout<<"Your height is "<<height<<" inches"<<endl;
double heightMeters = height * InchesConverseToMeters;
cout<<"Your height is "<<heightMeters<<" Meters"<<endl;
cout<<"Please enter your weight____pound ";
cin>>pound;
double weight = pound / poundConverseToKilogram;
cout<<"Your weight is "<<weight<<" kg"<<endl;
double BMI = weight / pow(heightMeters,2);
cout<<"Your BMI is "<<BMI<<endl;
return 0;
}
/*第三题*/
#include<iostream>
using namespace std;
int main()
{
const double degreeToMinute = 60;
const double MinuteToSecond = 60;
cout<<"Enter a latitude in degrees,minutes, and seconds:"<<endl;
int degrees,minutes,seconds;
cout<<"First, enter the degrees: ";
cin>>degrees;
cout<<"Next, enter the minutes of arc: ";
cin>>minutes;
cout<<"Finally, enter the seconds of arc: ";
cin>>seconds;
double converseDegrees = degrees + minutes / degreeToMinute + seconds / (degreeToMinute * MinuteToSecond);
cout<<degrees<<" degrees, "<<minutes<<" minutes, "<<seconds<<" seconds = "<<converseDegrees<<" degrees"<<endl;
return 0;
}
/*第四题*/
#include<iostream>
using namespace std;
int main()
{
const int hourOfDay = 24;
const int minuteOfHour = 60;
const int secondOfMinute = 60;
long long Init_seconds;
cout<<"Enter the number of seconds: ";
cin>>Init_seconds;
long days,hours,minutes,seconds;
seconds = Init_seconds % secondOfMinute;//40=31600000%60
minutes = Init_seconds / secondOfMinute;//526666=3160000/60
minutes = minutes % minuteOfHour;//46=526666%60
hours = (Init_seconds / secondOfMinute) / minuteOfHour;//8777=526666/60
hours = hours % hourOfDay;//17=8777%24
days = ((Init_seconds / secondOfMinute) / minuteOfHour) / hourOfDay;//365=8777/24
cout<<Init_seconds<<" seconds = "<<days<<" days, "<<hours<<" hours, "<<minutes<<" minutes, "<<seconds<<" seconds."<<endl;
return 0;
}
/*第五题*/
#include<iostream>
using namespace std;
int main()
{
long long popOfWorld,popOfUS;
cout<<"Enter the world's population: ";
cin>>popOfWorld;
cout<<"Enter the population of the US: ";
cin>>popOfUS;
double percentWorldUS = (double)popOfUS / popOfWorld;
cout<<"The population of the US is "<<percentWorldUS*100<<"% of the world population";
return 0;
}
/*第六题*/
#include<iostream>
using namespace std;
int main()
{
cout<<"请选择单位 1.英里和加仑;2.公里和升"<<endl;
int n;
cin>>n;
if(n==1)
{
cout<<"请输入驱车里程(英里)和使用汽油量(加仑):_________(用空格隔开)";
double miles,gallon,LPK;//LPK是油耗的缩写
cin>>miles>>gallon;
LPK = miles / gallon;
cout<<"油耗为 "<<LPK<<"(英里/加仑)"<<endl;
}
else if(n==2)
{
cout<<"请输入驱车里程(公里)和使用汽油量(升):_________(用空格隔开)";
double km,litres,LPK;//LPK是油耗的缩写
cin>>km>>litres;
LPK = litres / (km/100);
cout<<"油耗为 "<<LPK<<"(升/100公里)"<<endl;
}
return 0;
}
/*第七题*/
#include<iostream>
using namespace std;
int main()
{
const double kmToMiles = 62.14;
const double gallonToL = 3.875;
cout<<"请输入汽车的耗油量(升/100公里)";
double LPKOfE,LPKOfUS;
cin>>LPKOfE;
LPKOfUS = (gallonToL*kmToMiles)/LPKOfE;
cout<<LPKOfE<<"L/100km等于"<<LPKOfUS<<"英里/加仑"<<endl;
return 0;
}