C++primerplus(第6版)中文版编程练习答案(word版)(2020年12月16日整理).pptx

上传人:摩西的****12 文档编号:156457085 上传时间:2020-12-18 格式:PPTX 页数:197 大小:476.37KB
返回 下载 相关 举报
C++primerplus(第6版)中文版编程练习答案(word版)(2020年12月16日整理).pptx_第1页
第1页 / 共197页
C++primerplus(第6版)中文版编程练习答案(word版)(2020年12月16日整理).pptx_第2页
第2页 / 共197页
C++primerplus(第6版)中文版编程练习答案(word版)(2020年12月16日整理).pptx_第3页
第3页 / 共197页
C++primerplus(第6版)中文版编程练习答案(word版)(2020年12月16日整理).pptx_第4页
第4页 / 共197页
C++primerplus(第6版)中文版编程练习答案(word版)(2020年12月16日整理).pptx_第5页
第5页 / 共197页
点击查看更多>>
资源描述

《C++primerplus(第6版)中文版编程练习答案(word版)(2020年12月16日整理).pptx》由会员分享,可在线阅读,更多相关《C++primerplus(第6版)中文版编程练习答案(word版)(2020年12月16日整理).pptx(197页珍藏版)》请在金锄头文库上搜索。

1、第二章:开始学习 C+,/ex2.1-display your name andaddress #include int main(void) using namespace std; cout double fur2yd(double); int main() using namespace std; coutfur; cout void mice(); void see(); using namespace std; int main() mice(); mice(); see(); see(); return 0; ,1,2,void mice() cout int main() usi

2、ng 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 Fahrenheit.endl; return 0;

3、 double C2F(double t) return 1.8*t+32; ,/ex2.6-convert the light years valve to astronomical units-把光年转换为天文单位 #include double convert(double);/函数原型 int main() using namespace std; coutlight_years; double astro_units; astro_units=convert(light_years); cout void show(); main() using namespace std; sho

4、w(); return 0; void show() using namespace std; int h,m; couth; coutm; coutTime:h:mendl;,第三章:处理数据 /ex3.1将身高用英尺(feet)和英寸(inch)表示,3,4,#include const 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=h

5、t_inch%inch_per_feet;/取余 cout const int inch_per_feet=12; const double meter_per_inch=0.0254; const double pound_per_kilogram=2.2; int main() using namespace std; 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; doub

6、le wt_kilogram; wt_kilogram=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);,5,cout const int minutes_per_degree=60; const int seconds_

7、per_minute=60; int main() using namespace std; coutdegree; coutminute; coutsecond; double show_in_degree; show_in_degree=(double)degree+(double)minute/minutes_per_degree+(double)second/mi nutes_per_degree/seconds_per_minute;,minutes,secondseconds,coutdegreedegrees,minute =show_in_degree degreesn; re

8、turn 0; ,/ex3.4 #include const int hours_per_day=24; const intminutes_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

9、%hours_per_day; Minute=seconds/seconds_per_minute%minutes_per_hour;,6,Second=seconds%seconds_per_minute;,=Daydays,Hour,hours,Minute,coutsecondsseconds minutes,Second secondsn; return 0; ,/ex3.5 #include int main() using namespace std; coutworld_population; coutUS_population; double percentage; perce

10、ntage=(double)US_population/world_population*100; cout int main() using namespace std; coutm_distance; coutm_gasoline; coutk_distance; coutk_gasoline; coutIn European style:your can used 100*k_gasoline/k_distance liters of petrol per 100 kilometersn;,return 0; /ex3.7automobile gasoline consumption-耗

11、油量-欧洲风格(L/100Km)转换成美国风格(mpg) #include int main() using namespace std; coutEuro_style; cout int main() using namespace std; coutUS_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 figur

12、e in U.S. style(miles pergallon):19 Converts to European style(miles per gallon): 19 mpg = 12.6733L/100Km Press any key to continue 第四章 复合类型,7,8,display,theinformationof,/ex4.1 student,#include const int Asize=20; using namespace std; struct student/定义结构描述 char firstnameAsize; char lastnameAsize; ch

13、ar grade; int age; ; void display(student);/函数原型放在结构描述后 int main() coutlcg.grade; coutlcg.age; display(lcg); return 0; void display(student name) cout #include int main() using namespace std;,string name,dessert; coutsbumpc();/修改后的 break; ex4.3 输入其名和姓,并组合显示 #include #include const int Asize=20; int

14、main() using namespace std; char fnameAsize; char lnameAsize; char fullname2*Asize+1; cout #include const int Asize = 20; int main(),9,10, using namespace std; char firstnameAsize; char lastname50; cout Enter your first name: ; cin.getline(firstname,Asize); cout Enter your last name: ; cin.getline(l

15、astname,50); strcat(lastname, ); strncat(lastname,firstname,Asize); cout Heres the information in a single string: lastname endl; return 0; ,/ex4.4 使用 string 对象 存储、显示组合结果 #include #include int main() using namespace std; string fname,lname,attach,fullname; cout const int Asize=20; struct CandyBar ch

16、ar brandAsize; double weight; int calory;,11,; int main() using namespace std; CandyBar snack=Mocha Munch,2.3,350; cout const int Asize=20; struct CandyBar char brandAsize; double weight; int calory; ; int main() using namespace std; CandyBar snack3= Mocha Munch,2.3,350, XuFuJi,1.1,300, Alps,0.4,100 ; for(int i=0;i #include const int Size=

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

当前位置:首页 > 办公文档 > 其它办公文档

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