C++课后答案之选择结构程序设计

上传人:M****1 文档编号:431730068 上传时间:2024-02-07 格式:DOC 页数:16 大小:236.01KB
返回 下载 相关 举报
C++课后答案之选择结构程序设计_第1页
第1页 / 共16页
C++课后答案之选择结构程序设计_第2页
第2页 / 共16页
C++课后答案之选择结构程序设计_第3页
第3页 / 共16页
C++课后答案之选择结构程序设计_第4页
第4页 / 共16页
C++课后答案之选择结构程序设计_第5页
第5页 / 共16页
点击查看更多>>
资源描述

《C++课后答案之选择结构程序设计》由会员分享,可在线阅读,更多相关《C++课后答案之选择结构程序设计(16页珍藏版)》请在金锄头文库上搜索。

1、实验报告实验名称:选择结构程序设计实验时间:2012.11.2实验目的:完成习题实验指导书89页,熟练掌握选择结构的编程1 程序流程图:#includevoid main () int a,b; couta; b=a%2; if(b=1) cout该数为奇数endl; else cout该数为偶数endl;2#includevoid main () int a,b,c; couta; b=a%3; if(b=0) c=a*a*a; coutcyesendl; else c=a*a; coutcnoendl; 3#include#includevoid main ()double a,b,c,d

2、,x1,x2,t;coutabc;d=b*b-4*a*c;t=2*a;if(d0)x1=(-b+sqrt(d)/t;x2=(-b-sqrt(d)/t;coutx1=x1x2=x20)coutX1=-b/t+sqrt(-d)/tiendl;coutX2=-b/t-sqrt(-d)/tiendl;else cout计算不出两个相等的实根;4#includevoid main ()float x ,y;coutx;if(x1) y=x*x-1; else if (x10) y=2*x-1; else y=3*x-11; couty=yendl;5#includevoid main ()int a,b

3、,c;coutabc;if(ab)if(ac)coutmax=aendl;elsecoutmax=cc)coutmax=bendl;else coutmax=cendl;6#includevoid main () char m, a=A, b=B,c=C,d=D,e=E; coutm;switch (m) case A :cout90100endl;break; case B :cout8089endl;break; case C :cout7079endl;break; case D :cout6069endl;break; case E :cout059endl;break;7#inclu

4、de#include#includevoid main ()double a,b,c,area,perimeter,s;coutabc;s=1/2.0*(a+b+c);if(a+bc) if(a+cb) area=sqrt(s*(s-a)*(s-b)*(s-c); perimeter=a+b+c; coutsetiosflags(ios:fixed)setprecision(2);coutarea=areaperimeterperimeterendl; else cout这些边不能构成三角形endl; else cout这些边不能构成三角形endl; 8#includevoid main()i

5、nt a,b,c;couta;b=a%3;c=a%7;if(b=0) if(c=0) cout是3的倍数也是7的倍数。endl; else cout是3的倍数,不是7的倍数.endl;else if(c=0) cout不是3的倍数,但是7的倍数。endl; else cout既不是3的倍数,也不是7的倍数。endl;9#include#includevoid main () double salary ,tax, b;coutsalary;b=salary-850;if (salary=850) tax=0; else if (salary=1350) tax=0.05*b; else if

6、(salary=2850) tax=0.1*b; else if (salary=5850) tax=0.15*b; else tax=0.2*b;coutsetiosflags(ios:fixed)setprecision(2);couttax=taxendl;10#include void main ()int num,g ,s,ww,w,q,b;coutnum;if(num10) ww=1; else if (num100) ww=3; else if(num1000) ww=4; else if (num100000) ww=5; cout位数wwendl; /计算各位数字 w=num

7、/10000; q=(num-w*10000)/1000; b=(num-w*10000-q*1000)/100; s=(num-w*10000-q*1000-b*100)/10; g=num%10; cout顺序输出每位数字:; switch(ww) case 5: coutw,q,b,s,gendl; cout逆序输出:g,s,b,q,wendl; break; case 4: coutq,b,s,gendl; cout逆序输出:g,s,b,qendl; break; case 3: coutb,s,gendl; cout逆序输出:g,s,bendl; break; case 2: cou

8、ts,gendl; cout逆序输出:g,sendl; break; case 1: coutgendl;cout逆序输出:gendl; break; 11#includevoid main () int a,b,c,m;coutabc; m=b; b=a; a=c; c=m; coutabb)if(ac)coutmax=aendl;elsecoutmax=cc)coutmax=bendl;else coutmax=cendl; 总结:分清else和if的层次关系,该加括号加括号。用数学函数时记的写#include,sin(),sqrt(0.不能丢。注意程序语言的结构,要有严密的思维。不能有低

9、级错误出现。以下是大学体验英语综合教程2(第三版)课后翻译答案Unit11. 任何年满18岁的人都有资格投票。(be eligible to, vote)Answer:Anyone over the age of 18 is eligible to vote.2. 每学期开学前,这些奖学金的申请表格就会由学校发给每一个学生。(apply for, scholarship)Answer:A form to apply for these scholarships is sent by the university to every student before the start of ever

10、y semester.3. 遵照医生的建议,我决定戒烟。(on the advice of)Answer:On the advice of my doctor, I decided to give up smoking.4. 公园位于县城的正中央。(be located in)Answer:The park is located right in the center of town.5. 这所大学提供了我们所需的所有材料和设备。(facilities)Answer:The university provides all the materials and facilities we desire.1. 他们花了多年的时间寻找内心的平静,但是收效甚微。(search for)Answer:They spent many years searching for peace of mind, but with little success.2. 这种新药的成功研制已经使许多疾病

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

当前位置:首页 > 大杂烩/其它

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