cprimerplus第六版课后编程练习问题详解.doc
《cprimerplus第六版课后编程练习问题详解.doc》由会员分享,可在线阅读,更多相关《cprimerplus第六版课后编程练习问题详解.doc(19页珍藏版)》请在课桌文档上搜索。
1、word第二章:开始学习C+/ex2.1-display your name and address#includeint main(void)using namespace std;coutMy name is liao chunguang and I live in hunan chenzhou.n;/ex2.2-convert the furlong units to yard uints-把浪单位换位码单位#includedouble fur2yd(double);int main()using namespace std;coutfur;coutconvert the furlong
2、 to yardendl;double yd;yd=fur2yd(fur);coutfur furlong is yd yardendl;return 0;double fur2yd(double t)return 220*t;#includevoid mice();void see();using namespace std;int main()mice();mice();see();see();return 0;void mice()coutthree blind miceendl;void see()coutsee how they runendl;#includeint main()
3、using namespace std; coutage; int month; month=age*12; coutage years is month monthsendl; return 0;/ex2.5-convert the Celsius valve to Fahrenheit value#includedouble C2F(double);int main()using namespace std;coutC;double F;F=C2F(C);coutC degrees Celsius is F degrees Fahrenheit.endl;return 0;double C
4、2F(double t)return 1.8*t+32; /ex2.6-convert the light years valve to astronomical units-把光年转换为天文单位#includedouble convert(double);/函数原型int main()using namespace std;coutlight_years;double astro_units;astro_units=convert(light_years);coutlight_years light_years = astro_units astronomical units.endl;re
5、turn 0;double convert(double t)return 63240*t;/1 光年=63240 天文单位 #includevoid show();main()using namespace std;show();return 0;void show()using namespace std;int h,m;couth;coutm;coutTime:h:mendl;第三章:处理数据将身高用英尺(feet)和英寸(inch)表示#includeconst int inch_per_feet=12;/ const常量-1feet=12inches-1英尺=12英寸int main
6、()using namespace std;coutht_inch;int ht_feet=ht_inch/inch_per_feet;/取商int rm_inch=ht_inch%inch_per_feet;/取余coutyour height is ht_feet feet,and rm_inch inchesn;return 0;/ex3.2-计算相应的body mass index体重指数#includeconst int inch_per_feet=12;const double meter_per_inch=0.0254;const double pound_per_kilogra
7、m=2.2;int main()using namespace std;coutPlease enter your height:endl;coutht_feet;coutht_inch;coutwt_pound;int inch;inch=ht_feet*inch_per_feet+ht_inch;double ht_meter;ht_meter=inch*meter_per_inch;double wt_kilogram;wt_kilogram=wt_pound/pound_per_kilogram;coutendl;coutYour pensonal body information a
8、s follows:endl;cout身高:inch(英尺inch)n身高:ht_meter(米meter)n体重:wt_kilogram(千克kilogram)n;double BMI;BMI=wt_kilogram/(ht_meter*ht_meter);coutyour Body Mass Index(体重指数) is BMIendl;return 0;/ex3.3 以度,分,秒输入,以度输出#includeconst int minutes_per_degree=60;const int seconds_per_minute=60;int main()using namespace s
9、td;coutEnter a latitude in degrees,minutes,and seconds:n;coutdegree;coutminute;coutsecond;double show_in_degree;show_in_degree=(double)degree+(double)minute/minutes_per_degree+(double)second/minutes_per_degree/seconds_per_minute;coutdegree degrees,minute minutes,secondseconds =show_in_degree degrees
10、n;return 0;#includeconst int hours_per_day=24;const int minutes_per_hour=60;const int seconds_per_minute=60;int main()using namespace std;coutseconds;int Day,Hour,Minute,Second;Day=seconds/seconds_per_minute/minutes_per_hour/hours_per_day;Hour=seconds/seconds_per_minute/minutes_per_hour%hours_per_da
11、y;Minute=seconds/seconds_per_minute%minutes_per_hour;Second=seconds%seconds_per_minute;coutsecondsseconds = Day days,Hour hours,Minute minutes,Second secondsn;return 0;#includeint main() using namespace std; coutworld_population; coutUS_population; double percentage; percentage=(double)US_population
12、/world_population*100; coutThe population of the US is percentage% of the world population.n; return 0; 汽车耗油量-美国(mpg)or欧洲风格(L/100Km)#includeint main()using namespace std;coutm_distance;coutm_gasoline;coutYour car can run m_distance/m_gasoline miles per gallonn;coutputing by European style:n;coutk_di
13、stance;coutk_gasoline;coutIn European style:your can used 100*k_gasoline/k_distance liters of petrol per 100 kilometersn;return 0;/ex3.7 automobile gasoline consumption-耗油量-欧洲风格(L/100Km)转换成美国风格(mpg)#includeint main()using namespace std;coutEnter the automobile gasoline consumption figure innEuro_sty
14、le;coutConverts to U.S. style(miles per gallon):endl;coutEuro_style L/100Km = 62.14*3.875/Euro_style mpgn;return 0;/ Note that 100 kilometers is 62.14 miles, and 1 gallon is 3.875 liters. /Thus, 19 mpg is about 12.4 L/100Km, and 27 mpg is about 8.7 L/100Km.Enter the automobile gasoline consumption f
15、igure inConverts to U.S. style(miles per gallon):12.4 L/100Km = 19.4187 mpgPress any key to continue/ ex3.7 automobile gasoline consumption-耗油量-美国风格(mpg)转换成欧洲风格(L/100Km)#includeint main()using namespace std;coutEnter the automobile gasoline consumption figure innUS_style;coutConverts to European sty
16、le(miles per gallon):endl;coutUS_style mpg = 62.14*3.875/US_styleL/100Kmn;return 0;/ Enter the automobile gasoline consumption figure inU.S. style(miles per gallon):19Converts to European style(miles per gallon):Press any key to continue第四章 复合类型/ex4.1 display the information of student#includeconst
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- cprimerplus 第六 课后 编程 练习 问题 详解
![提示](https://www.desk33.com/images/bang_tan.gif)
链接地址:https://www.desk33.com/p-21224.html