//3-1
#include <iostream>
int main()
{
using namespace std;
const int conver=12;
int height;
cout<<"Enter your height in inches:___\b\b\b";
cin>>height;
cout<<"Your height is "<<height/conver<<" feet "<<height%conver<<" inches."<<endl;
return 0;
}
//3-2
#include <iostream>
int main()
{
using namespace std;
const int inch_per_feet=12;
const float pound_per_kg=2.2;
const float meter_per_inch=0.0254;
float height_f;
float height_i;
float height_m;
float weight;
cout<<"Enter your height in X feet and y inches,plesae."<<endl;
cout<<"feet:";
cin>>height_f;
cout<<"inches:";
cin>>height_i;
cout<<"Enter your mass in pound:";
cin>>weight;
height_m=(height_i+height_f*inch_per_feet)*meter_per_inch;
weight/=pound_per_kg;
cout<<"Your BMI is "<<weight/(height_m*height_m)<<endl;
return 0;
}
//3-3
#include <iostream>
int main()
{
using namespace std;
const int conver=60;
float mdegree;
float mmin;
float msec;
cout<<"Enter a latitude in degrees,minutes,and seconds:"<<endl;
cout<<"First,enter the degrees:"; cin>>mdegree;
cout<<"Next,enter the minutes of arc:"; cin>>mmin;
cout<<"Finally,enter the seconds of arc:"; cin>>msec;
cout<<mdegree<<" degrees, "<<mmin<<" minutes, "<<msec<<" seconds = ";
cout<<mdegree+mmin/conver+msec/(conver*conver)<<" degrees"<<endl;
return 0;
}
//3-4
#include <iostream>
int main()
{
using namespace std;
const int hour_per_day=24;
const int min_per_hour=60;
const int sec_per_min=60;
long long msec;
cout<<"Enter the number of seconds:";
cin>>msec;
cout<<msec<<" seconds = "<<msec/(hour_per_day*min_per_hour*sec_per_min)<<" days, ";
msec%=(hour_per_day*min_per_hour*sec_per_min);
cout<<msec/(min_per_hour*sec_per_min)<<" hours, ";
msec%=(min_per_hour*sec_per_min);
cout<<msec/sec_per_min<<" minutes, ";
msec%=sec_per_min;
cout<<msec<<" seconds"<<endl;
return 0;
}
//3-5
#include <iostream>
int main()
{
using namespace std;
long long popul_w;//世界人口
long long popul_a;//美国人口
cout<<"Enter the world's population:";
cin>>popul_w;
cout<<"Enter the population of the US:";
cin>>popul_a;
cout<<"The population of the US is "<<float(popul_a)/float(popul_w)*100;
cout<<"% of the world population."<<endl;
return 0;
}
//3-6
#include <iostream>
int main()
{
using namespace std;
float dist;
float fuel;
cout<<"Enter your distanse in km:";
cin>>dist;
cout<<"Enter the consumption of fuel in litre:";
cin>>fuel;
cout<<"The fuel consumption per 100km is "<<fuel/dist*100<<endl;
return 0;
}
//3-7
#include <iostream>
int main()
{
using namespace std;
const float mile_per_100km=62.14;
const float liter_per_gal=3.875;
float dist_g;
float fuel_g;
float consum_e;//欧洲单位 (litre per 100km);
cout<<"Enter your car's fuel consumpion(litre per 100km):";
cin>>consum_e;
dist_g=mile_per_100km;
fuel_g=consum_e/liter_per_gal;
cout<<"The US stanfrad fuel consumpton is "<<dist_g/fuel_g<<endl;
return 0;
}