cprimerplus(第六版)课后编程练习答案资料.pdf

上传人:白大夫 文档编号:5402541 上传时间:2020-05-01 格式:PDF 页数:19 大小:101.22KB
返回 下载 相关 举报
cprimerplus(第六版)课后编程练习答案资料.pdf_第1页
第1页 / 共19页
cprimerplus(第六版)课后编程练习答案资料.pdf_第2页
第2页 / 共19页
cprimerplus(第六版)课后编程练习答案资料.pdf_第3页
第3页 / 共19页
cprimerplus(第六版)课后编程练习答案资料.pdf_第4页
第4页 / 共19页
cprimerplus(第六版)课后编程练习答案资料.pdf_第5页
第5页 / 共19页
点击查看更多>>
资源描述

《cprimerplus(第六版)课后编程练习答案资料.pdf》由会员分享,可在线阅读,更多相关《cprimerplus(第六版)课后编程练习答案资料.pdf(19页珍藏版)》请在三一文库上搜索。

1、第二章:开始学习C+ /ex2.1-display your name and address #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; void mice() cout int main() using na

2、mespace std; coutage; int month; month=age*12; cout double C2F(double); int main() using namespace std; coutC; double F; F=C2F(C); cout double convert(double);/函数原型 int main() using namespace std; coutlight_years; double astro_units; astro_units=convert(light_years); cout void show(); main() using n

3、amespace std; show(); return 0; void show() using namespace std; int h,m; couth; coutm; cout 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=ht_inch%inch_per_feet;/取余 cout const int inch_

4、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; double wt_kilogram; wt_kilogram=wt_pound/pound_pe

5、r_kilogram; cout const int minutes_per_degree=60; const int seconds_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; cout co

6、nst 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/hours_per_day; Hour=seconds/seconds_per_minute/minutes_per_hour%hours_per_day; Minute=sec

7、onds/seconds_per_minute%minutes_per_hour; Second=seconds%seconds_per_minute; cout int main() using namespace std; coutworld_population; coutUS_population; double percentage; percentage=(double)US_population/world_population*100; cout int main() using namespace std; coutm_distance; coutm_gasoline; co

8、utk_distance; coutk_gasoline; cout int main() using namespace std; coutEuro_style; cout int main() using namespace std; coutUS_style; cout const int Asize=20; using namespace std; struct student/ 定义结构描述 char firstnameAsize; char lastnameAsize; char grade; int age; ; void display(student);/ 函数原型放在结构描

9、述后 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 main() using namespace std; char fnameAsize; char l

10、nameAsize; char fullname2*Asize+1; cout #include int main() using namespace std; string fname,lname,attach,fullname; cout const int Asize=20; struct CandyBar char brandAsize; double weight; int calory; ; int main() using namespace std; CandyBar snack=“Mocha Munch“,2.3,350; cout const int Asize=20; s

11、truct 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=20; struct pizza/ 声明结构 char companySize; double diameter; double weight; ; int main() using na

12、mespace std; pizza pie;/ 创建一个名为pie 的结构变量 coutpie.diameter; coutpie.weight; cout #include const int Size=20; struct pizza/ 声明结构 char companySize; double diameter; double weight; ; int main() using namespace std; pizza *pie=new pizza;/ 使用 new 创建动态结构 coutpie-diameter; cin.get();/ 读取下一个字符 coutcompany,Si

13、ze); coutpie-weight; coutdiametercompanyweight #include using namespace std; struct CandyBar string brand; double weight; int calory; ; int main() CandyBar *snack= new CandyBar3; snack0.brand=“A“;/ 单个初始化由new 动态分配的内存 snack0.weight=1.1; snack0.calory=200; snack1.brand=“B“; snack1.weight=2.2; snack1.ca

14、lory=400; snack2.brand=“C“; snack2.weight=4.4; snack2.calory=500; for(int i=0;i int main() using namespace std; const int Size = 3; int successSize; cout success0success1success2; cout #include int main() using namespace std; arrayad=0; cout ad0ad1ad2; cout int main() using namespace std; coutnum1nu

15、m2; int sum=0; for(int temp=num1;temp #include int main() using namespace std; arrayad=0; ad1=ad0=1L; for(int i=2;i int main() using namespace std; coutnum) cout int main() using namespace std; double sum1,sum2; sum1=sum2=0.0; int year=0; while(sum2 const int MONTHS = 12; const char* monthsMONTHS=“J

16、anuary“,“February“,“March“,“April“,“May“,“June“,“July“,“August“,“Sept ember“,“October“,“November“,“December“; int main() using namespace std; int salesMONTHS,sum=0; for(int i=0;isalesi; sum+=salesi; cout const int MONTHS = 12; const char* monthsMONTHS=“January“,“February“,“March“,“April“,“May“,“June

17、“,“July“,“August“,“Sept ember“,“October“,“November“,“December“; const char* years3=“第一年 “,“ 第二年 “,“ 第三年 “; int main() using namespace std; int year_sale3,sum=0,sales3MONTHS; for(int i=0;isalesij; temp+=salesij; year_salei=temp; sum+=year_salei; for(int i=0;i #include using namespace std; struct car

18、string name; int year; ; int main() coutnum).get(); car* ps=new carnum; for(int i=0;ipsi.year).get(); cout #include int main() using namespace std; char word20; int sum=0; coutword; while(strcmp(word,“done“) sum+; cinword; cout #include int main() using namespace std; string word; int sum=0; coutword; while(word!=“done“) sum+; cinword; cout int main() using namespace std; coutnum; for(int i=0;i1;j-) cout“.“; for(int k=0;k=i;+k) cout“*“; coutendl; return 0;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 其他


经营许可证编号:宁ICP备18001539号-1