ImageVerifierCode 换一换
格式:DOCX , 页数:25 ,大小:20.10KB ,
资源ID:7390433      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/7390433.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(c++primerplus第六版课后编程练习测试参考答案.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

c++primerplus第六版课后编程练习测试参考答案.docx

1、c+primerplus第六版课后编程练习测试参考答案第二章:开始学习C+/ex2.1-displayyournameandaddress#includeintmain(void) usingnamespacestd; coutMynameisliaochunguangandIliveinhunanchenzhou.n”;/ex2.2-convertthefurlongunitstoyarduints-把浪单位换位码单位#includedoublefur2yd(double);intmain() usingnamespacestd; coutfur; coutconvertthefurlong

2、toyardendl;doubleyd; yd=fur2yd(fur); coutfurfurlongisydyardendl; return0;doublefur2yd(doublet) return220*t;/ex2.3-每个函数都被调用两次#includevoidmice();voidsee();usingnamespacestd;intmain() mice(); mice(); see(); see(); return0;voidmice() coutthreeblindmiceendl;voidsee() coutseehowtheyrunendl;/ex2.4#includei

3、ntmain()usingnamespacestd;coutage;intmonth;month=age*12;coutageyearsismonthmonthsendl;return0;/ex2.5-converttheCelsiusvalvetoFahrenheitvalue#includedoubleC2F(double);intmain()usingnamespacestd;coutC;doubleF;F=C2F(C);coutCdegreesCelsiusisFdegreesFahrenheit.endl;return0;doubleC2F(doublet)return1.8*t+3

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

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

6、ntht_feet=ht_inch/inch_per_feet;/取商 intrm_inch=ht_inch%inch_per_feet;/取余 coutyourheightisht_feetfeet,and rm_inchinchesn; return0;/ex3.2-计算相应的bodymassindex(体重指数)#includeconstintinch_per_feet=12;constdoublemeter_per_inch=0.0254;constdoublepound_per_kilogram=2.2;intmain() usingnamespacestd; coutPleasee

7、nteryourheight:endl; coutht_feet; coutht_inch; coutwt_pound; intinch; inch=ht_feet*inch_per_feet+ht_inch; doubleht_meter; ht_meter=inch*meter_per_inch; doublewt_kilogram; wt_kilogram=wt_pound/pound_per_kilogram; coutendl; coutYourpensonalbodyinformationasfollows:endl; cout身高:inch(英尺inch)n身高:ht_meter

8、(米meter)n 体重:wt_kilogram(千克kilogram)n; doubleBMI; BMI=wt_kilogram/(ht_meter*ht_meter); coutyourBodyMassIndex(体重指数)isBMIendl; return0;/ex3.3以度,分,秒输入,以度输出#includeconstintminutes_per_degree=60;constintseconds_per_minute=60;intmain() usingnamespacestd; coutEnteralatitudeindegrees,minutes,andseconds:n; c

9、outdegree; coutminute; coutsecond; doubleshow_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#includeconstinthours_per_day=24;constint

10、minutes_per_hour=60;constintseconds_per_minute=60;intmain() usingnamespacestd; coutseconds; intDay,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_minute%minutes_per_hour; Se

11、cond=seconds%seconds_per_minute; coutsecondsseconds=Daydays,Hourhours,Minuteminutes,Secondsecondsn; return0;/ex3.5#includeintmain()usingnamespacestd;coutworld_population;coutUS_population;doublepercentage;percentage=(double)US_population/world_population*100;coutThepopulationoftheUSispercentage%ofth

12、eworldpopulation.n;return0;/ex3.6?汽车耗油量-美国(mpg)or欧洲风格(L/100Km)#includeintmain()?usingnamespacestd;?coutm_distance;?coutm_gasoline;?coutYourcarcanrunm_distance/m_gasolinemilespergallonn;?coutComputingbyEuropeanstyle:n;?coutk_distance;?coutk_gasoline;?coutInEuropeanstyle:yourcanused100*k_gasoline/k_di

13、stancelitersofpetrolper100kilometersn;?return0;/ex3.7automobilegasolineconsumption-耗油量-欧洲风格(L/100Km)转换成美国风格(mpg)#includeintmain() usingnamespacestd; coutEntertheautomobilegasolineconsumptionfigureinn Euro_style; coutConvertstoU.S.style(milespergallon):endl; coutEuro_styleL/100Km=62.14*3.875/Euro_sty

14、lempgn; return0;/Notethat100kilometersis62.14miles,and1gallonis3.875liters./Thus,19mpgisabout12.4L/100Km,and27mpgisabout8.7L/100Km.EntertheautomobilegasolineconsumptionfigureinEuropeanstyle(litersper100kilometers):12.4ConvertstoU.S.style(milespergallon):12.4L/100Km=19.4187mpgPressanykeytocontinue/ex

15、3.7automobilegasolineconsumption-耗油量-美国风格(mpg)转换成欧洲风格(L/100Km)#includeintmain() usingnamespacestd; coutEntertheautomobilegasolineconsumptionfigureinn US_style; coutConvertstoEuropeanstyle(milespergallon):endl; coutUS_stylempg=62.14*3.875/US_styleL/100Kmn; return0;/Entertheautomobilegasolineconsumpti

16、onfigureinU.S.style(milespergallon):19ConvertstoEuropeanstyle(milespergallon):19mpg=12.6733L/100KmPressanykeytocontinue第四章复合类型/ex4.1displaytheinformationofstudent#includeconstintAsize=20;usingnamespacestd;structstudent/定义结构描述 charfirstnameAsize; charlastnameAsize; chargrade; intage;voiddisplay(stude

17、nt);/函数原型放在结构描述后intmain() coutwhatisyourfirstname?endl; studentlcg;/创建结构变量(结构数据对象) cin.getline(lcg.firstname,Asize); coutwhatisyourlastname?endl; cin.getline(lcg.lastname,Asize); coutwhatlettergradedoyoudeserve?lcg.grade; coutwhatisyourage?lcg.age; display(lcg); return0;voiddisplay(studentname) cout

18、Name:name.firstname,name.lastnameendl; coutGrade:char(name.grade+1)endl; coutAge:name.ageendl;/ex4.2usethestring-classinsteadofchar-array#include#includeintmain() usingnamespacestd; stringname,dessert; coutEnteryourname:n; getline(cin,name); coutEnteryourfavoritedessert:n; getline(cin,dessert); cout

19、Ihavesomedeliciousdessert; coutforyou,namesbumpc();/修改后的break;ex4.3输入其名和姓,并组合显示#include#includeconstintAsize=20;intmain() usingnamespacestd; charfnameAsize; charlnameAsize; charfullname2*Asize+1; coutEnteryourfirstname:;/输入名字,存储在fname数组中 cin.getline(fname,Asize); coutEnteryourlastname:;/输入姓,存储在lname

20、数组中 cin.getline(lname,Asize); strncpy(fullname,lname,Asize);/把姓lname复制到fullname空数组中 strcat(fullname,);/把“,”附加到上述fullname尾部 strncat(fullname,fname,Asize);/把fname名字附加到上述fullname尾部 fullname2*Asize=0;/为防止字符型数组溢出,在数组结尾添加结束符 coutHerestheinformationinasinglestring:fullnameendl;/显示组合结果 return0;/ex4.4使用strin

21、g对象存储、显示组合结果#include#includeintmain() usingnamespacestd; stringfname,lname,attach,fullname; coutEnteryourfirstname:; getline(cin,fname);/note:将一行输入读取到string类对象中使用的是getline(cin,str) /它没有使用句点表示法,所以不是类方法 coutEnteryourlastname:; getline(cin,lname); attach=,; fullname=lname+attach+fname; coutHerestheinfo

22、rmationinasinglestring:fullnameendl; return0;/ex4.5declareastructandinitializeit声明结果并创建一个变量#includeconstintAsize=20;structCandyBar charbrandAsize; doubleweight; intcalory;intmain() usingnamespacestd; CandyBarsnack=MochaMunch,2.3,350; coutHerestheinformationofsnack:n; coutbrand:snack.brandendl; coutw

23、eight:snack.weightendl; coutcalory:snack.caloryendl; return0;/ex4.6结构数组的声明及初始化#includeconstintAsize=20;structCandyBar charbrandAsize; doubleweight; intcalory;intmain() usingnamespacestd; CandyBarsnack3= MochaMunch,2.3,350, XuFuJi,1.1,300, Alps,0.4,100 ;for(inti=0;i3;i+)/利用for循环来显示snack变量的内容 coutsnacki.brandendl snacki.weightendl snack

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1