c++课后答案

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

第一章答案一、选择填空12345678910CBDADADDAC二、判断下列描述的正确性,对者划√,错者划×。123456789101112√√××√××√√√××四、析下列程序的输出结果1.BeiJjingShangHaiTianJing2.Inputa,b:85A=8,b=5A-b=33.D=5,c=m五、编译下列程序,改正所出现的各种错误信息,并分析输出结果:1.#includeiostream.hvoidmain(){cout”Thisisastring!”;}输出结果:Thisisastring!2.#includeiostream.hvoidmain(){intx;cinx;intp=x*x;cout”p=”p”\n”;}输出结果:3p=93、#includeiostream.hvoidmain(){inti,j;i=5;j=3;intk=i+j;cout”i+j=”k”\n”;}输出结果:I+j=8第二章答案二、选择填空12345678910ADCAC无ACCA11121314151617181920DDDAAADBAC21222324DDAD二、判断下列描述的正确性,对者划√,错者划×。12345678910×√×√√×√√√√111213141516√×××××三、计算下列各表达式的值(下列各表达式是相互独立的,不考虑前面对后面的影响。)1.ABCDEF47389429496723810422.ABCDEF6501-161203.ABCDEF0,5,31,5,33,1,315,10,48,8,31,5,34.ABCD025005.ABCDEF2022-3011三、3、#includeiostream.hvoidmain(){floatc,f;cout”华氏温度:”;cinf;c=(f-32)*5/9;cout”摄氏温度:”cendl;}4、#includeiostream.hconstfloatr=1.60934;voidmain(){floatm,I;cout”公里数:”;cinm;I=r*m;cout”英里数:”Iendl;}5、#includeiostream.hvoidmain(){intn,m;cout”输入一个整数:”;cinn;m=n|15;cout”结果为:”mendl;}第三章答案三、选择填空12345678910BDAAABADDA1112131415CDCAC二、判断下列描述的正确性,对者划√,错者划×。12345678910√×××√×××××11121314151617181920××√×××√√√√三、分析下列程序的输出结果。1.13.52.203.134.1475.35Ok!6.677.1111211331146411510105116152015611721353521718.31-19.1,210.SWITCH⊙WAMP四、1、#includeiostream.hvoidmain(){intI=1,s=0;while(I=99){s=s+I;I+=2;}cout”s=”sendl;}2、#includeiostream.hvoidmain(){intI=13,m;while(I100){if(I%13==0)m=I;I+=13;}cout”m=”mendl;}3、#includeiostream.hvoidmain(){intr,I,j;cout”I=”;cinI;cout”j=”;cinj;if(Ij)r=I,I=j,j=r;r=I%j;while(r){I=j;j=r;r=I%j;}cout”最大公约数:”jendl;}#includeiostream.hvoidmain(){intx,y,s;cout”输入两个整数:”;cinIj;s=x;while(1){if(s%y==0)break;s+=x;}cout”最小公倍数:”sendl;}4、#includeiostream.hvoidmain(){intI,m,n,k;floats=0;m=1;n=2;for(I=1;I=15;I++){s=s+1.0*n/m;k=m;n=n;n=k+n;}cout”s=”sendl;}5、#includeiostream.hvoidmain(){intI,n=1;longints=0;for(I=1;I=10;I++){n=n*I;s=s+n;}cout”s=”sendl;}6、#includeiostream.h#includemath.hvoidmain(){intI,n=0;for(I=1;I=(int)(sqrt(1000));I++){n++;if(n%8==)coutI*Iendl;elsecoutI*I”,”;}coutendl;}8、#includeiostream.hvoidmain(){doublex,y;coutPleaseinputx:;cinx;if(x1)y=x;elseif(x=10)y=x-5;elsey=x+5;coutx=x,y=yendl;}9、#includeiostream.h#includemath.hvoidmain(){doublea,b,c,d,x1,x2;coutPleaseinputa,b,c:;cinabc;d=b*b-4*a*c;if(a==0)cout不是二次方程!\n;elseif(d==0){x1=x2=-b/2*a;cout有两个相等实根x1=x2=x1endl;}elseif(d0){x1=(-b+sqrt(d))/2*a;x2=(-b-sqrt(d))/2*a;cout有两个不等实根x1=x1,x2=x2endl;}else{cout有两个共轭复根:;coutx1=(-b/2*a)+(sqrt(-d)/2*a)iendl;coutx2=(-b/2*a)-(sqrt(-d)/2*a)iendl;}}10、#includeiostream.hvoidmain(){for(inti=1;i=5;i++){for(intj=1;j=5-i;j++)cout;//先打印空格for(intk=1;k=2*i-1;k++)cout*;//再打印*coutendl;//换行}//打印上半部分for(i=1;i=4;i++){for(intj=1;j=i;j++)cout;//先打印空格for(intk=1;k=9-2*i;k++)cout*;//再打印*coutendl;//换行}//打印下半部分}第四章答案一、选择填空12345678910ADBDDCCDCA1112131415BCADC二、判断下列描述的正确性,对者划√,错者划×。12345678910√√×√×√××√√11121314151617181920×√√√×√××√√三、分析下列程序的输出结果。1.5811142.253.10+2+1=1320+2+2=2430+2+3=3540+2+4=464.6,115.5!+4!+3!+2!+1!=1536.6,6,611.sum1=13sum2=18sum3=2312.72013.a=5,b=8a=8,b=514.1015.u1998abcd16.ff(double):88.18ff(int):97四、8、#includeiostream.h#includestring.h#includemalloc.hchar*func(int,int);voidmain(){coutendl;coutfunc(3,251)endl;}char*func(intn,ints){char*p=(char*)malloc(1);if(n==1){charstr[2];str[0]=’0’+s;str[1]=’\0’;returnstr;}else{intn1=s%10;ints1=s/10;*p=’0’+n1;returnstrcat(func(n-1,s1),p,1);}}9、#includeiostream.h#includemath.hdoublefunc(int,int,int,int);doublefunc(double,double,double,double);voidmain(){coutfunc(2,2,5,5)”,”;coutfunc(2.0,2.0,5.0,5.0)endl;}doublefunc(intx1,inty1,intx2,inty2){returnsqrt((x1-x2)*(x1-x2(+(y1-y2)*(y1-y2));}doublefunc(doublex1,doubley1,doublex2,doubley2){returnsqrt((x1-x2)*(x1-x2(+(y1-y2)*(y1-y2));}11、#includeiostream.hintfunc(intn=2);voidmain(){coutfunc(1)”,”;coutfunc()”,”;coutfunc(3)endl;}intfunc(intn){ints=0;for(intI=1;I=10;I++)s=n*(1+s);returns;}第五章答案一、选择填空12345678910ACDCDACADA二、判断下列描述的正确性,对者划√,错者划×。12345678910√√××√√×√×√三、分析下列程序的输出结果。4.Defaultconstructorcalled.Constructorcalled.A=0,b=0A=4,b=85.A=7,b=96.1047.1035,789,5048.1{}{1,2,3,4,5,6,7,8}1{11,12,13,14,15,16,17,18,19}{19,18,17,16,15,14,13,12,11}第六章答案一、选择填空123456789101112CABCCDBCADCB二、判断下列描述的正确性,对者划√,错者划×。123456789101112√√√√×√√√×√××三、分析下列程序的输出结果。1.Starting1...Defaultconstructorcalled.Defaultconstructorcalled.Defaultconstructorcalled.Ending1...Starting2...Constructor:a=1,b=2Constructor:a=3,b=4Constructor:a=5,b=6Ending2...Destructorcalled.A=5,b=6Destructorcalled.A=3,b=4Destructorcalled.A=1,b=2Destructorcalled.A=5,b=6Destructorcalled.A=3,b=4Destructorcalled.A=1,b=22.Defaultconstructorcalled.Defaultconstructorcalled.Defaultconstructorcalled.Defaultconstructorcalled.Destructorcalled.Constructor1called.Destructorcalled.Constructor2called.Destructorcalled.X=0,y=0X=5,y=0X=2,y=3Destructorcalled.Destructorcalled.Destructorc

1 / 13
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功