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

上传人:灯火****19 文档编号:121895896 上传时间:2020-02-27 格式:DOC 页数:197 大小:145.76KB
返回 下载 相关 举报
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、第二章:开始学习 C+/ex2.1-display your name and address#include int 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-把浪单位换位码单位#include double fur2yd(double); int main()using namespace std;coutfur;coutconvert the furlon

2、g to yardendl; double yd;yd=fur2yd(fur);coutfur furlong is yd yardendl; return 0;double fur2yd(double t)return 220*t;/ex2.3-每个函数都被调用两次#include void mice();void see();using namespace std; int main()mice();mice();see();see(); return 0;void mice()coutthree blind miceendl;void see()coutsee how they rune

3、ndl;/ex2.4#include int main()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#include double C2F(double); int main()using namespace std;coutC; double F; F=C2F(C);coutC degrees Celsius is F degrees Fa

4、hrenheit.endl; return 0;double C2F(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

5、_units astronomical units.endl; return 0;doubleconvert(double t)return 63240*t;/1 光年=63240 天文单位/ex2.7-显示用户输入的小时数和分钟数#include void show();main()using namespace std; show();return 0;void show()using namespace std; int h,m;couth;coutm; coutTime:h:mendl;第三章:处理数据/ex3.1将身高用英尺(feet)和英寸(inch)表示#includeconst

6、 int inch_per_feet=12;/const 常量-1feet=12inches-1 英尺=12 英寸int main()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_fee

7、t=12;const double meter_per_inch=0.0254; const double pound_per_kilogram=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_kilogr

8、am=wt_pound/pound_per_kilogram; coutendl;coutYour pensonal body information as 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 i

9、nt minutes_per_degree=60; const int seconds_per_minute=60; int main()using namespace std;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/se

10、conds_per_minute;coutdegreedegrees,minuteminutes,secondseconds=show_in_degree degreesn; return 0;/ex3.4#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_minu

11、te/minutes_per_hour/hours_per_day; Hour=seconds/seconds_per_minute/minutes_per_hour%hours_per_day; Minute=seconds/seconds_per_minute%minutes_per_hour;Second=seconds%seconds_per_minute;coutsecondsseconds=Daydays,Hourhours,Minute minutes,Second secondsn;return 0;/ex3.5#include int main()using namespace std;coutworld_population;coutEnter the population of the US:; lo

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

当前位置:首页 > 中学教育 > 教学课件 > 初中课件

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