电大C++期末考试复习资料小抄

上传人:1777****777 文档编号:38752562 上传时间:2021-11-08 格式:DOC 页数:42 大小:304.52KB
收藏 版权申诉 举报 下载
电大C++期末考试复习资料小抄_第1页
第1页 / 共42页
电大C++期末考试复习资料小抄_第2页
第2页 / 共42页
电大C++期末考试复习资料小抄_第3页
第3页 / 共42页
资源描述:

《电大C++期末考试复习资料小抄》由会员分享,可在线阅读,更多相关《电大C++期末考试复习资料小抄(42页珍藏版)》请在装配图网上搜索。

1、专业好文档三、给出下列程序运行后的输出结果 1. #include void main() int s=0; for(int i=1;i+) if(s50) break; if(i%2=0) s+=i; couti,s=i,sendl; 2. #include void main() char a=abcdabcabfgacd; int i1=0, i2=0, i=0; while(ai) if(ai=a) i1+; if(ai=b) i2+; i+; couti1 i2endl; 3. #include void main() int a9=2,4,6,8,10,12,14,16,18; f

2、or(int i=0;i9;i+) coutsetw(5)*(a+i); if(i+1)%3=0) coutendl; 4. #include void LE(int* a, int* b) int x=*a; *a=*b; *b=x; cout*a *bendl; void main() int x=10, y=25; LE(&x,&y); coutx yendl; 5. #include class A int a,b; public: A() a=b=0; A(int aa, int bb) a=aa; b=bb; couta bendl; ; void main() A x,y(2,3

3、),z(4,5); 6#include template class FF TT a1, a2, a3; public: FF(TT b1, TT b2, TT b3) a1=b1; a2=b2; a3=b3; TT Sum() return a1+a2+a3; ; void main() FF x(2,3,4),y(5,7,9); coutx.Sum() y.Sum()endl; 7. #include void SB(char ch) switch(ch) case A: case a: coutwell!;break; case B: case b: coutgood!;break; c

4、ase C: case c: coutpass!;break; default: coutbad!;break; void main() char a1=b,a2=C,a3=f; SB(a1);SB(a2);SB(a3);SB(A); coutendl; 8. #include #include void main() char* a5=student,worker,cadre,soldier,peasant; char *p1, *p2; p1=p2=a0; for(int i=0;i0) p1=ai; if(strcmp(ai, p2)0) p2=ai; coutp1 p2endl; 9.

5、 #include int a=5; void main() int a=10, b=20; couta bendl; int a=0,b=0; for(int i=1; i6; i+) a+=i; b+=a; couta b :aendl; couta bendl; 10. #include int LB(int *a, int n) int s=1; for(int i=0;in;i+) s*=*a+; return s; void main() int a=1,2,3,4,5,6,7,8; int b=LB(a,5)+LB(&a3,3); coutb=bendl; 11. #includ

6、e #include struct Worker char name15; /姓名 int age; /年龄 float pay; /工资 ; void main() Worker x; char *t=liouting; int d=38; float f=493; strcpy(x.name,t); x.age=d; x.pay=f; coutx.name x.age x.payendl; 12. #include class A int a; public: A(int aa=0) a=aa; A() coutDestructor A!aendl; ; class B: public A

7、 int b; public: B(int aa=0, int bb=0): A(aa) b=bb; B() coutDestructor B!bendl; ; void main() B x(5), y(6,7); /后定义的变量将先被释放 三、给出下列程序运行后的输出结果1. i,s=15,562. 4 33. 2 4 6 8 10 12 14 16 184. 25 10 25 105. 2 3 4 56. 9 217. good!pass!bad!well!8. worker cadre9. 10 20 15 35 5 10 2010. b=24011. liouting 38 4931

8、2. Destructor B!7 Destructor A!6 Destructor B!0 Destructor A!5三、写出下列每个程序运行后的输出结果(每小题6分,共30分) 1. #include void main() int n=5, sum=0; while(n0) sum+=n; n-; coutsum=sumendl; 运行结果: 2. #include const int N=6; void main() int aN=76,83,54,62,40,65; int max=a0; for(int i=1;imax) max=ai; coutmax=maxendl; 运行

9、结果: 3. #include void main() int a8=4,8,15,16,20,30,48,62; int *p=a, s=0; while(pa+8) s+=*p; p+=3; coutsendl; 运行结果: 4.#include int LF(int x, int y) x=x+y; y=x+y; return x+y; void main() int x=2, y=3; coutLF(x,y)endl; 运行结果: 5. #include class A int a,b; public: A() a=b=0; A(int aa, int bb) a=aa; b=bb;

10、int Sum()return a+b; ; void main() A x,y(3,4); coutx.Sum() y.Sum()endl; 运行结果:三、写出下列每个程序运行后的输出结果(每小题6分,共30分)1. sum=152. max=833. 684. 135. 0 7 /每个数据3分三、写出下列每个程序运行后的输出结果(每小题6分,共30分) 1. #include #include int SD(int a, int b, char op) switch(op) case +: return a+b; case -: return a-b; default: cout操作符op

11、出错,退出运行!;exit(1); void main() int x=20, y=6; coutSD(x,y,+) SD(x,y,-)endl; 运行结果: 2. #include #include void main() char* a5=student,worker,cadre,soldier,apen; char *p1; p1=a0; for(int i=1;i0) p1=ai; coutp1endl; 运行结果: 3. #include int WF(int x, int y) x=x+y;x=13; y=x+y;y=13+5=18; return x+y; void main()

12、 coutWF(8,5)endl; 运行结果: 4. #include const int n=9; void main() int an=2,4,6,8,10,12,14,16,18; int s=0; for(int i=0; in; i+) if(i%3=0) s+=ai; cout”s=”sendl; 运行结果: 5. #include void main() int* d=new int5; int i; for(i=0;i5;i+) di=2*i+1; coutdi ; coutendl; deleted; 运行结果:三、写出下列每个程序运行后的输出结果(每小题6分,共30分)1.

13、 26 14 /每个数据3分2. worker3. 314. 245. 1 3 5 7 9 /每个数据1分,全对给6分三、写出下列每个程序运行后的输出结果(每小题6分,共30分) 1. #include void main() int n=5, sum=0; while(n) sum+=n; n-; cout”sum=”sumendl; 运行结果: 2. #include const int N=6; void main() int aN=76,83,54,62,40,65; int c1, c2; c1=c2=a0; for(int i=1;ic1) c1=ai; else if(aic2)

14、 c2=ai; coutc1 c2endl; 运行结果: 3. #include void main() int a8=4,8,15,16,20,30,48,62; int *p=a; do cout*p ; p+=3; while(pa+8); coutendl; 运行结果: 4.#include int LF(int x, int y) x=x+y; y=x+y; return x+y; void main() int x=5, y=8; coutLF(x,y) LF(10,6)endl; 运行结果: 5. #include class A int a,b; public: A() a=b

15、=0; A(int aa, int bb) a=aa; b=bb; couta bendl; ; void main() A x,y(2,3); 运行结果:三、写出下列每个程序运行后的输出结果(每小题6分,共30分)1. sum=152. 83 40 /每个数据3分3. 4 16 48 /每个数据2分4. 34 38 /每个数据3分5. 2 3 /每个数据3分三、写出下列每个程序运行后的输出结果(每小题6分,共30分) 1. #include void SB(char ch) switch(ch) case A: case a: cout优! ; break; case B: case b:

16、cout良! ; break; case C: case c: cout通过! ; break; default: cout不通过!;break; void main() SB(A); SB(c); coutendl; 运行结果: 2. #include void main() int a6=36,25,48,14,55,40; int x=a0; for(int i=1;ix) x=ai; cout”x=”xendl; 运行结果: 3. #include void main() int a6=32,53,27,19,12,45; for(int *p=a; pa+6; p+) if(*p%3

17、=0) cout*p ; coutendl; 运行结果: 4. #include int* LG(int m) int* a=new int(m+5); return a; void main() int n1=12; int *b=LG(n1); cout*bendl; delete b; 运行结果: 5. #include #include struct Worker char name15; int age; float pay; ; void main() Worker x; strcpy(x.name, WeiRong); x.age=45; x.pay=3275; coutx.na

18、me x.age x.payendl; 运行结果:三、写出下列每个程序运行后的输出结果(每小题6分,共30分)1. 优! 通过! /每个数据占3分2. x=553. 27 12 45 /每个数据占2分4. 175. WeiRong 45 3275三、写出下列每个程序运行后的输出结果(每小题6分,共30分) 1. #include void main() int n=4,y=1; while(n-) y*=3; couty=yendl; 运行结果: 2. #include void main() int a8=2,8,10,5,12,7,9,20; int c=0, i=0; while(i10

19、) c+; i+; coutc=cendl; 运行结果:c=2 3. #include void main() int a5=3,6,9,12,8; for(int *p=a; p8) cout*p ; 运行结果:9 12 4. #include int LA(int a, int n) int s=0; for(int i=0;in;i+) s+=ai; return s; void main() int a5=5,2,8,6,4; int b=LA(a,5); coutb=bendl; 运行结果:b=25 5. #include struct AB char aa15; int bb; ;

20、 void main() AB a4=Apple,25,Peach,40,Pear,36,Tomato,62; for(int i=0;i4;i+) if(ai.bb40) coutai.aa ; coutendl; 运行结果:三、写出下列每个程序运行后的输出结果(每小题6分,共30分)1. y=812. c=23. 9 124. b=255. Apple Pear三、写出下列每个程序运行后的输出结果(每小题6分,共30分) 1. #includevoid main()int n=4,y=1;while(n-) y*=3;couty=yendl; 运行结果:y=81 2. #includevo

21、id main()int a8=2,8,10,5,12,7,9,20;int c=0,i=0;while(i8)if(ai10) c+;i+;coutc=cendl; 运行结果:c=5 3.#includevoid main()int a5=3,6,9,12,8;for(int *p=a;i10) cout*pendl; 运行结果:12 4. #includeint LA(int a,int n)int s=0;for(int i=0;in;i+)s+=ai;return s;void main()int a5=5,2,8,6,4;int b=LA(a,5);coutb=bendl; 运行结果

22、:b=25 5. #includestruct ABchar a15;int bb;void main()AB a4=Apple,25,Peach,40,Pear,36,Tomato,62;for(int i=0;i=40) coutai.aa ;coutendl; 运行结果:Peach Tomato三、写出下列每个程序运行后的输出结果(每小题6分,共30分)1. y=812. c=53. 124. b=255. Pear Tomato三、写出下列每个程序运行后的输出结果(每小题6分,共30分) 1. #include void main() int n=5, sum=0; while(n)

23、sum+=n*n; n-; coutsum=sumendl; 运行结果: 2. #include const int N=6; void main() int aN=76,83,54,62,40,65; int c1=0; for(int i=0;i=60) c1+; coutc1=c1endl; 运行结果: 3. #include void main() int a8=4,8,15,16,20,30,48,62; int *p=a,s=0; while(pa+8) s+=*p; p+=3; coutsendl; 运行结果: 4. #include int a=10, b=15, c; voi

24、d main() c=a+b; int b=a+20; c+=a+b; coutcendl; 输出结果: 5. #include void FF(int a, int n) int i,x; for(i=0; in/2; i+) x=ai; ai=an-1-i; an-1-i=x; void main() int a8=6,19,4,12,20,5,18,25; FF(a,8); couta0,a1endl; 输出结果:三、写出下列每个程序运行后的输出结果(每小题6分,共30分)1. sum=552. 4 3. 68 4. 655. 25,18三、写出下列每个程序运行后的输出结果(每小题6分,

25、共30分) 1. #include void main() int n=5, sum=0; while(n) sum+=n; n-; cout”sum=”sumendl; 运行结果: 2. #include const int N=6; void main() int aN=76,83,54,62,40,65; int c1, c2; c1=c2=a0; for(int i=1;ic1) c1=ai; else if(aic2) c2=ai; coutc1 c2endl; 运行结果: 3. #include void main() int a8=4,8,15,16,20,30,48,62; i

26、nt *p=a; while(pa+8) cout*p ; p+=3; coutendl; 运行结果: 4.#include int LF(int x, int y) x=x+y; y=x+y; return x+y; void main() int x=5, y=8; coutLF(1,2) LF(3,4)endl; 运行结果: 5. #include class A int a,b; public: A() a=b=0; A(int aa, int bb) a=aa; b=bb; couta bendl; ; void main() A x,y(3,4); 运行结果:三、写出下列每个程序运

27、行后的输出结果(每小题6分,共30分)1. sum=152. 83 40 /每个数据3分3. 4 16 48 /每个数据2分4. 8 18 /每个数据3分5. 3 4 /每个数据3分三、写出下列每个程序运行后的输出结果(每小题6分,共30分) 1. #include void main() int s=0; for(int i=1;i=8;i+=2) s+=i*i; couts=sendl; 输出结果: 2. #include void main() int i=1,s=0; while(s15) s+=i+; couti,sendl; 输出结果: 3. #include void main(

28、) int a8=36,25,48,14,55,20,47,82; int c1=0, c2=0; for(int i=0; i8; i+) if(ai50) c1+; else c2+; coutc1 c2endl; 输出结果: 4. #include int LB(int *a, int n) int p=1; for(int i=0;in;i+) p*=*a; a+; return p; void main() int a5=1,2,3,4,3; coutLB(a,5)endl; 输出结果: 5. #include struct Worker char name15; /姓名 int a

29、ge; /年龄 float pay; /工资 ; void main() Worker x=wangfong,46,1640; Worker y, *p; y=x; p=&x; couty.age+10 pay*2endl; 输出结果:三、写出下列每个程序运行后的输出结果(每小题6分,共30分)1. s=842. 6,15 /每个数据3分3. 6 2 /每个数据3分4. 72 /6分5. 56 3280 /每个数据3分三、写出下列每个程序运行后的输出结果(每小题6分,共30分) 1. #include void main() int s1=0, s2=1; for(int i=1; i=6;

30、i+) s1+=i; s2*=i; couts1,s2endl; 输出结果: 2. #include void main() int a10=68,79,86,65,46,94,37,78,60,53; int c=0; for(int i=0;i=60) c+; cout”c=”cendl; 输出结果: 3. #include void main() int a34=1,2,7,8,5,6,11,15,9,20,3,4; int m=a00; for(int i=0;i3;i+) for(int j=0;jm) m=aij; coutmendl; 输出结果: 4. #include void

31、 main() int a=10, b=15; couta b ; a*=3; int b=a+20; couta b ; couta bendl; 输出结果: 5. #include void main() int a8=6,19,4,12,20,5,18,25; int* p=a; for(p=a; pa+8;p+) if(*p10) cout*p ; coutendl; 输出结果:三、写出下列每个程序运行后的输出结果(每小题6分,共30分)1. 21,720 /每个数据3分2. c=73. 204. 10 15 30 50 30 15 /每个数据占1分,全对6分5. 6 4 5 /每个数

32、据占2分,全对6分三、写出下列每个程序运行后的输出结果(每小题6分,共30分) 1. #includevoid main()int n=4,y=1;while(n-) y*=3;couty=yendl; 运行结果: 2. #includevoid main()int a8=2,8,10,5,12,7,9,20;int c=0,i=0;while(i8)if(ai10) c+;i+;coutc=cendl; 运行结果: 3.#includevoid main()int a5=3,6,9,12,8;for(int *p=a;p10) cout*pendl; 运行结果: 4. #includeint

33、 LA(int a,int n)int s=0;for(int i=0;in;i+)s+=ai;return s;void main()int a5=5,2,8,6,4;int b=LA(a,5);coutb=bendl; 运行结果: 5. #includestruct ABchar a15;int bb;void main()AB a4=Apple,25,Peach,40,Pear,36,Tomato,62;for(int i=0;i=40) coutai.a ;coutendl; 运行结果:三、写出下列每个程序运行后的输出结果(每小题6分,共30分)1. y=812. c=53. 124. b=25

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!