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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

C++primerplus第6版中文版编程练习答案.docx

1、C+primerplus第6版中文版编程练习答案第二章:开始学习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;co

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

3、e how they runendl;/ex2.4#includeint 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#includedouble C2F(double);int main()using namespace std;coutC;double F;F=C2F(C);coutC degrees Celsius is F deg

4、rees Fahrenheit.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 = a

5、stro_units astronomical units.endl;return 0;double convert(double t)return 63240*t;/1 光年=63240 天文单位/ex2.7-显示用户输入的小时数和分钟数#includevoid 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_feet=12

7、;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_kilogram=wt_poun

8、d/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 int minutes_per_deg

9、ree=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/seconds_per_minute;coutd

10、egree degrees,minute minutes,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_minute/minutes_per_hour/hour

11、s_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 = Day days,Hour hours,Minuteminutes,Second secondsn;return 0;/ex3.5#includeint main()using namespace std;coutworld_populati

12、on;coutUS_population;double percentage;percentage=(double)US_population/world_population*100;coutThe population of the US is percentage% of the world population.n;return 0;/ex3.6 汽车耗油量-美国(mpg)or 欧洲风格(L/100Km)#includeint main()using namespace std;coutm_distance;coutm_gasoline;coutYour car can run m_d

13、istance/m_gasoline miles per gallonn;coutComputing by European style:n;coutk_distance;coutk_gasoline;coutIn European style:your can used 100*k_gasoline/k_distance liters of petrolper 100 kilometersn;return 0;/ex3.7 automobile gasoline consumption-耗油量-欧洲风格(L/100Km)转换成美国风格(mpg)#includeint main()using

14、namespace std;coutEnter the automobile gasoline consumption figure innEuro_style;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

15、, and 27 mpg is about 8.7 L/100Km.Enter the automobile gasoline consumption figure inEuropean style(liters per 100 kilometers):12.4Converts 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)#include

16、int main()using namespace std;coutEnter the automobile gasoline consumption figure innUS_style;coutConverts to European style(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 t

17、o European style(miles per gallon):19 mpg = 12.6733L/100KmPress any key to continue第四章复合类型/ex4.1 display the information ofstudent#includeconst int Asize=20;using namespace std;struct student/定义结构描述char firstnameAsize;char lastnameAsize;char grade;int age;void display(student);/函数原型放在结构描述后int main()

18、coutwhat is your first name?endl;student lcg;/创建结构变量结构数据对象cin.getline(lcg.firstname,Asize);coutwhat is your last name?endl;cin.getline(lcg.lastname,Asize);coutwhat letter grade do you deserve?lcg.grade;coutwhat is your age?lcg.age;display(lcg);return 0;void display(student name)coutName: name.firstn

19、ame,name.lastnameendl;coutGrade:char(name.grade+1)endl;coutAge:name.ageendl;/ex4.2 use the string-class instead of char-array#include#includeint main()using namespace std;string name,dessert;coutEnter your name: n;getline(cin,name);coutEnter your favorite dessert: n;getline(cin,dessert);coutI have s

20、ome delicious dessert;cout for you, namesbumpc();/修改后的break; ex4.3 输入其名和姓,并组合显示#include#includeconst int Asize=20;int main()using namespace std;char fnameAsize;char lnameAsize;char fullname2*Asize+1;coutEnter your first name:;/输入名字,存储在fname数组中cin.getline(fname,Asize);coutEnter your last name:;/输入姓,存

21、储在lname数组中cin.getline(lname,Asize);strncpy(fullname,lname,Asize);/把姓lname 复制到fullname 空数组中strcat(fullname, );/把“, ”附加到上述fullname 尾部strncat(fullname,fname,Asize);/把fname 名字附加到上述fullname 尾部fullname2*Asize=0;/为防止字符型数组溢出,在数组结尾添加结束符coutHeres the information in a single string:fullnameendl;/显示组合结果return 0

22、;#define _CRT_SECURE_NO_WARNINGS#include #include const int Asize = 20;int main()using namespace std;char firstnameAsize;char lastname50;cout Enter your first name: ;cin.getline(firstname,Asize);cout Enter your last name: ;cin.getline(lastname,50);strcat(lastname, );strncat(lastname,firstname,Asize)

23、;cout Heres the information in a single string: lastname endl;return 0;/ex4.4 使用string 对象存储、显示组合结果#include#includeint main()using namespace std;string fname,lname,attach,fullname;coutEnter your first name:;getline(cin,fname);/note:将一行输入读取到string 类对象中使用的是getline(cin,str)/它没有使用句点表示法,所以不是类方法coutEnter your last name:;getline(cin,lname);attach=, ;fullname=ln

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2