C++ Primer Plus(第六版)第三章课后习题

C++ Primer Plus(第六版)第三章课后习题

3.7.1

#include
int main()
{
using namespace std;
double height;
const int change=12;
int foot, inch;
cout <<“Please enter your height:_______\b\b\b\b\b\b\b” ;
cin >> height;
foot= height;
inch= (height- foot)*change;
cout <<“Your height is " << foot <<” foots and “<<inch<<” inches."<<endl;
return 0;
}

3.7.2

#include
int main()
{
using namespace std;
const double foot_inch=12, inch_meter=0.0254, pound_kilogram=1.0/2.2;
double meter, kilogram;
int foot, inch, pound;
cout <<" Please enter your height(feet and inches):\b\b\b\b\b";
cin >> foot;
cout <<"
\b\b\b\b\b";
cin >> inch;
cout <<" Please enter your weight(pounds):_____\b\b\b\b";
cin >>pound;
meter=(foot_inch*foot+inch)inch_meter;
kilogram=pound_kilogram
pound;
double BMI=kilogram/meter;
cout << "Your BMI is: "<< BMI <<endl;
return 0;
}

3.7.3

#include
int main()
{
using namespace std;
const double degree_minute=60, minute_second=60;
int degree, minute, second;
cout <<" Enter a latitude in degrees, minutes, and seconds:\n";
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;
double change=degree+(second/minute_second+minute)/degree_minute;
cout << degree << " degrees, “<< minute <<” minutes, “<< second <<” seconds = "
<< change <<” degrees”;
return 0;
}

3.7.4

#include
int main()
{
using namespace std;
const int day_hour=24, hour_minute=60,minute_second=60;
long second;
cout << "Enter the number of seconds: “;
cin >> second;
int day, hour, minute, seconds;
day=second/(day_hourhour_minuteminute_second);
long a=second-day*(day_hourhour_minuteminute_second);
hour=a/(hour_minuteminute_second);
a=a-hour
(hour_minuteminute_second);
minute=a/minute_second;
a=a-minute
minute_second;
seconds=a;
cout << second <<” seconds= “<< day << " days, “<< hour << " hours, " << minute << " minutes, " << seconds <<” seconds”;

return 0;

}

3.7.5

#include
int main()
{
using namespace std;
long long a, b;
cout << "Enter the world’s population: ";
cin >> a;
cout << "Enter the population of the US: ";
cin >> b;
double c=(double) b/ (double) a*100;
cout << "The population of the US is " << c << “% of the world population.”;
return 0;
}

3.7.6

#include
int main()
{
using namespace std;
double mile, gallon;
cout << “Enter the distance that you drive:”;
cin >> mile;
cout << “Enter the weight of gasline that you use:”;
cin >> gallon;
double mile_gallon=mile/gallon;
cout << “When you consume one gallon of gasline, you can go far as " << mile_gallon << " miles”;
return 0;
}

3.7.7

#include
int main()
{
using namespace std;
const double k_m=62.14,g_l=3.875;
double mpg,l_km;
cout <<“Enter the oil consuption in European style:”;
cin >> l_km;
mpg=1/l_kmk_mg_l;
cout << “The oil consuption in American style is " << mpg <<” mpg";
return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值