第一题:
#include <iostream>
using namespace std;
int main()
{
const double inchtofoot=0.833333;
cout<<"Please enter your height___\b\b\b";
int inch;
cin>>inch;
cout<<"Your height is "<<int(inch*inchtofoot)<<" feet "
<<inch*inchtofoot-int(inch*inchtofoot)<<" inches"<<endl;
return 0;
}
第二题:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double inch;
double foot;
double pound;
const int foottoinch=12;
const double inchtometer=0.0254;
const double poundtokg=2.2;
cout<<"Please enter your height and weight:";
cin>>inch;
cin>>foot;
cin>>pound;
double meter;
double kg;
meter=(inch+foot*foottoinch)*inchtometer;
cout<<meter<<endl;
kg=pound/poundtokg;
cout<<"Your BMI is "<<kg/(meter*meter)<<endl;
return 0;
}
第三题:
#include <iostream>
using namespace std;
int main()
{
double degree,minute,second;
cout<<"Enter a latitude in degrees, minutes, and seconds: "<<endl;
cout<<"First, enter the degrees: ";
cin>>degree;
cout<<"Next, enter the minutes of arc: ";
cin>>minute;
cout<<"Finally, enter the seconds of arc: ";
cin>>second;
cout<<degree<<" degrees, "<<minute<<" minutes, "<<second<<" seconds = ";
degree=degree+minute/60+second/3600;
cout<<degree<<" degrees"<<endl;
return 0;
}
第四题:
#include <iostream>
using namespace std;
int main()
{
long second;
cout<<"Enter the number of seconds:";
cin>>second;
int day,hour,minute;
day=second/(60*60*24);
hour=second/(60*60)-day*24;
minute=second/60-hour*60-day*24*60;
cout<<second<<" seconds = "<<day<<" days "<<hour<<" hours "<<minute<<" minutes ";
second=second%60;
cout<<second<<" seconds";
return 0;
}
第五题:
#include <iostream>
using namespace std;
int main()
{
long long population_w;
long long population_us;
cout<<"Enter the world's population:";
cin>>population_w;
cout<<"Enter thr population of US:";
cin>>population_us;
cout<<"The population of the US is "<<population_us*(double)100/population_w<<"% of the world population"<<endl;
return 0;
}
第六题:
#include <iostream>
using namespace std;
int main()
{
double mile;
double gallon;
double km;
double litre;
cout<<"Enter the mile:";
cin>>mile;
cout<<"Enter the gallon:";
cin>>gallon;
cout<<"1 gallon "<<mile/gallon<<" mile"<<endl;
cout<<"Enter the km:";
cin>>km;
cout<<"Enter the litre:";
cin>>litre;
cout<<"1 litre "<<km/litre<<" km"<<endl;
return 0;
}
第七题:(待定)
#include <iostream>
using namespace std;
int main()
{
double kpl;
double mpg;
cout<<"Enter the kpl:";
cin>>kpl;
mpg=62.14/(kpl/3.875);
cout<<"the mpg is "<<mpg;
return 0;
}