《C++ Primer Plus 第六版》编程练习参考答案(第三章)
2018-12-06 18:19
330 查看
第三章
第一题:
[code]#include <iostream> using namespace std; const int TransFactor=12; int main() { int height=0; int inch=0; int foot=0; cout<<"Enter the height of you in inch: ___\b\b\b"; cin>>height; foot=height/TransFactor; inch=height%TransFactor; cout<<"Your height is "<<foot<<" foot and "<<inch<<" inch"; }
第二题:
[code]#include <iostream> using namespace std; const double HeightTrans=0.0254; const double WeightTrans=2.2; const int InchFootTrans=12; int main() { int inch=0; int foot=0; double pound=0; double meter=0; double kilogram=0; double BMI; cout<<"Enter the height of you in foot and inch: "; cin>>foot>>inch; meter=HeightTrans*(foot*InchFootTrans+inch); cout<<"Enter the weight of you in pound: "; cin>>pound; kilogram=pound/WeightTrans; BMI=kilogram/(meter*meter); cout<<"The BMI index of you is: "<<BMI; }
第三题:
[code]#include <iostream> using namespace std; const double TransFactor=60; int main() { double degrees=0; double minutes=0; double seconds=0; double degrees_trans=0; cout<<"Enter a latitude in degrees,minutes,and seconds: "<<endl; 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; degrees_trans=degrees+minutes/TransFactor+seconds/(TransFactor*TransFactor); cout<<degrees<<" degrees, "<<minutes<<" minutes, "<<seconds<<" seconds= " <<degrees_trans<<" degrees."; }
第四题:
[code]#include <iostream> using namespace std; const long TransFactorMinutes=60; const long TransFactorHours=60*60; const long TransFactorDays=60*60*24; int main() { long seconds_full=0; long days=0; long hours=0; long minutes=0; long seconds=0; cout<<"Enter the number of seconds: "; cin>>seconds_full; days=seconds_full/TransFactorDays; hours=(seconds_full%TransFactorDays)/TransFactorHours; minutes=((seconds_full%TransFactorDays)%TransFactorHours)/TransFactorMinutes; seconds=((seconds_full%TransFactorDays)%TransFactorHours)%TransFactorMinutes; cout<<seconds_full<<" seconds= "<<days<<" days, "<<hours<<" hours, " <<minutes<<" minutes, "<<seconds<<" seconds."; }
第五题:
[code]#include <iostream> using namespace std; int main() { long long USA=0; long long world=0; double percent=0; cout<<"Enter the world's population: "; cin>>world; cout<<"Enter the population of the US: "; cin>>USA; percent=((double)USA/world)*100; cout<<"The population of the US is " <<percent<<"% of the world population."; }
第六题:
[code]#include <iostream> using namespace std; int main() { double distance; double gasoline; double consumption; cout<<"Enter the distance in kilometer: "; cin>>distance; cout<<"Enter the gasoline in litre: "; cin>>gasoline; consumption=(gasoline/distance)*100; cout<<"The gasoline consumption of your car is " <<consumption<<" litre per 100 kilometer"; }
第七题:
[code]#include <iostream> using namespace std; const double DistanceTrans=62.14; const double GasolineTrans=3.875; int main() { double litre=0; double kilometer=0; double EUconsumption=0; double gallon=0; double mile=0; double USconsumption=0; cout<<"Enter the distance in kilometer: "; cin>>kilometer; cout<<"Enter the gasoline in litre: "; cin>>litre; EUconsumption=(litre/kilometer)*100; cout<<"In EU, The gasoline consumption of your car is " <<EUconsumption<<" litre per 100 kilometer"<<endl; gallon=litre/GasolineTrans; mile=(kilometer/100)*DistanceTrans; USconsumption=mile/gallon; cout<<"In the US, The gasoline consumption of your car is " <<USconsumption<<" mile per gallon"; }
相关文章推荐
- C++ Primer Plus(第六版)第四章编程练习参考答案
- c++ primer plus 第六版第三章编程练习答案
- C++ primer Plus(第六版)中文版 第三章 处理数据 编程练习答案
- 《C++ Primer Plus 第六版》编程练习参考答案(第四章)
- C++ Primer Plus第六版 第三章 编程练习答案
- 《C++ Primer Plus 第六版》编程练习参考答案(第六章)
- C++ Primer Plus (第六版)第六章编程练习参考答案
- C++ primer Plus(第六版)中文版 第五章 循环和关系表达式 编程练习答案
- C++ primer Plus(第六版)中文版 第九章 内存模型和名称空间 编程练习答案
- C++primer plus第六版课后编程练习答案6.2
- C++primer plus第六版课后编程练习答案11.2
- C++primer plus第六版课后编程练习答案13.3
- C++ primer Plus(第六版)中文版 第十章 对象和类 编程练习答案
- C++primer plus第六版课后编程练习答案3.2
- C++primer plus第六版课后编程练习答案4.2
- C++primer plus第六版课后编程练习答案7.9
- C++primer plus第六版课后编程练习答案8.5
- C++primer plus第六版课后编程练习答案10.1
- C++primer plus第六版课后编程练习答案3.3
- C++primer plus第六版课后编程练习答案5.1