C++--primer--plus(第6版)中文版--编程练习答案(word版)

上传人:pu****.1 文档编号:543461893 上传时间:2024-01-24 格式:DOC 页数:197 大小:646KB
返回 下载 相关 举报
C++--primer--plus(第6版)中文版--编程练习答案(word版)_第1页
第1页 / 共197页
C++--primer--plus(第6版)中文版--编程练习答案(word版)_第2页
第2页 / 共197页
C++--primer--plus(第6版)中文版--编程练习答案(word版)_第3页
第3页 / 共197页
C++--primer--plus(第6版)中文版--编程练习答案(word版)_第4页
第4页 / 共197页
C++--primer--plus(第6版)中文版--编程练习答案(word版)_第5页
第5页 / 共197页
点击查看更多>>
资源描述

《C++--primer--plus(第6版)中文版--编程练习答案(word版)》由会员分享,可在线阅读,更多相关《C++--primer--plus(第6版)中文版--编程练习答案(word版)(197页珍藏版)》请在金锄头文库上搜索。

1、 .wd.第二章:开场学习C+/ex2.1-display your name andaddress#includeintmain(void)using namespacestd;coutMy name is liao chunguang and I live in hunanchenzhou.n;/ex2.2-convertthefurlongunitstoyarduints-把浪单位换位码单位#include doublefur2yd(double); intmain()using namespacestd;coutfur;coutconvert the furlong toyardend

2、l; doubleyd;yd=fur2yd(fur);coutfur furlong is ydyardendl; return0;double fur2yd(doublet)return220*t;/ex2.3-每个函数都被调用两次#includevoidmice();voidsee();using namespacestd; intmain()mice();mice();see();see(); return0;voidmice()coutthree blindmiceendl;voidsee()coutsee how theyrunendl;/ex2.4#includeint main(

3、)usingnamespacestd;coutage;int month;month=age*12;coutage years is monthmonthsendl;return0;/ex2.5-converttheCelsiusvalvetoFahrenheitvalue#include doubleC2F(double); intmain()using namespacestd;coutC; doubleF; F=C2F(C);coutCdegreesCelsiusisFdegreesFahrenheit.endl; return0;double C2F(doublet)return1.8

4、*t+32;/ex2.6-convertthelightyearsvalvetoastronomicalunits-把光年转换为天文单位#includedoubleconvert(double);/函数原型 intmain()using namespacestd;coutlight_years; doubleastro_units;astro_units=convert(light_years);coutlight_yearslight_years=astro_unitsastronomicalunits.endl; return0;doubleconvert(doublet)return 6

5、3240*t;/1 光年=63240 天文单位/ex2.7-显示用户输入的小时数和分钟数#includevoidshow();main()using namespacestd; show();return0;voidshow()using namespacestd; inth,m;couth;coutm; coutTime:h:mendl;第三章:处理数据/ex3.1将身高用英尺(feet)和英寸(inch)表示#includeconst intinch_per_feet=12;/const 常量-1feet=12inches-1 英尺=12英寸intmain()using namespace

6、std;coutht_inch;intht_feet=ht_inch/inch_per_feet;/取商intrm_inch=ht_inch%inch_per_feet;/取余 coutyourheightisht_feetfeet,andrm_inchinchesn; return0;/ex3.2-计算相应的bodymassindex体重指数#includeconst intinch_per_feet=12;const doublemeter_per_inch=0.0254; const doublepound_per_kilogram=2.2; intmain()using namespa

7、cestd;coutPlease enter yourheight:endl;coutht_feet;coutht_inch;coutwt_pound;intinch;inch=ht_feet*inch_per_feet+ht_inch;double ht_meter; ht_meter=inch*meter_per_inch; doublewt_kilogram;wt_kilogram=wt_pound/pound_per_kilogram;coutendl;coutYour pensonal body information asfollows:endl; cout身高:inch(英尺in

8、ch)n身高:ht_meter(米meter)n体重:wt_kilogram(千克kilogram)n; doubleBMI; BMI=wt_kilogram/(ht_meter*ht_meter);coutyour Body Mass Index(体重指数) isBMIendl; return0;/ex3.3以度,分,秒输入,以度输出#includeconst intminutes_per_degree=60; const intseconds_per_minute=60; intmain()using namespacestd;coutEnter a latitude in degrees

9、,minutes,andseconds: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;coutdegreedegrees,minuteminutes,secondseconds=show_in_degreedegreesn; return0;/ex3.4#includeconst inthou

10、rs_per_day=24; const intminutes_per_hour=60;const intseconds_per_minute=60; intmain()using namespacestd;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_day;Minute=seconds/seconds_per_minu

11、te%minutes_per_hour;Second=seconds%seconds_per_minute;coutsecondsseconds=Daydays,Hourhours,Minute minutes,Secondsecondsn;return0;/ex3.5#includeint main()using namespace std;coutworld_population;coutUS_population;doublepercentage;percentage=(double)US_population/world_population*100;coutThe population of the US is percentage% of the worl

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 建筑/环境 > 施工组织

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号