C++ Primer Plus 第三章 课后编程练习题1-7

1 .

#include
int main()
{
using namespace std;
const double inch_foot = 0.0833333;
int myheight_in;
cout <<“请输入你的身高(英寸)______\b\b\b\b\b\b”;
cin >> myheight_in;
cout << “你的身高是 " << myheight_in * inch_foot <<” 英尺。" << endl;

return 0;

}

#include
int main()
{
using namespace std;
const int ft_in = 12;
const double in_m = 0.0254;
const double kg_pound = 2.2;
double my_height_ft;
double my_weight_lb;
double my_height_in;
cout << “请输入你的身高(英尺 英寸):”;
cin >> my_height_ft >> my_height_in;
cout << "请输入你的体重(磅): ";
cin >> my_weight_lb;
cout << "你的BMI值是: " << (my_weight_lb / kg_pound)/
(((my_height_ft * ft_in + my_height_in) * in_m) *
((my_height_ft * ft_in + my_height_in) * in_m)) << endl;

return 0;

}

#include
int main()
{
using namespace std;
const double Lat_d_m_s = 60.0;
int degree, minute, second;
double degrees;
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;
degrees = degree + minute/Lat_d_m_s + second/Lat_d_m_s/Lat_d_m_s;

cout <<degree <<" degrees, "<<minute <<" minutes, "
<<second <<" seconds = " <<degrees <<" degrees " <<endl;
return 0;

}

#include
int main()
{
using namespace std;
long seconds;
const short hou_min_sec = 60;
const short day_hou = 24;
double days,hours,minute,second;
cout <<“Enter the number of seconds: “;
cin >>seconds;
second = seconds % hou_min_sec;
minute = seconds / hou_min_sec % hou_min_sec;
hours = seconds / hou_min_sec / hou_min_sec % day_hou;
days = seconds / hou_min_sec / hou_min_sec / day_hou;
cout <<seconds <<” seconds = " <<int (days) <<” days, "
<<int (hours) <<" hours, " << int (minute) <<" minutes, "
<<int (second) <<" seconds" << endl;

return 0;

}

#include
int main()
{
using namespace std;
long long global_pop, usa_pop;
double proportion;
cout <<"Enter the world’s population: ";
cin >> global_pop;
cout <<"Enter the population of the US: “;
cin >> usa_pop;
proportion = 100.0 * usa_pop / global_pop;
cout <<“The population of the US is "
<<proportion <<”% of the world population.” << endl;

return 0;

}

#include
int main()
{
using namespace std;
double total_mil, fuel_con, fuel_con_hun;
cout <<"请输入总里程(公里): ";
cin >>total_mil;
cout <<"请输入耗油量(升): “;
cin >>fuel_con;
fuel_con_hun = fuel_con / total_mil * 100;
cout <<“你每100公里的耗油量是: " << fuel_con_hun <<” 升.” << endl;

return 0;

}

#include
int main()
{
using namespace std;
const double HunKm_mi = 62.14;
const double UsGal_l = 3.875;

double us_mpg ,hun_km;
cout <<"请输入每100公里的耗油量(升): ";
cin >>hun_km;
us_mpg = HunKm_mi / (hun_km / UsGal_l);

cout <<"100公里耗油量为 " <<hun_km <<"升 = "
<<int (us_mpg) <<" mpg." <<endl;

return 0;

}

发布了85 篇原创文章 · 获赞 1 · 访问量 1889

猜你喜欢

转载自blog.csdn.net/Tekkenwxp/article/details/103576766