2014年电大C++期末考试复习资料小抄.doc_第1页
2014年电大C++期末考试复习资料小抄.doc_第2页
2014年电大C++期末考试复习资料小抄.doc_第3页
2014年电大C++期末考试复习资料小抄.doc_第4页
2014年电大C++期末考试复习资料小抄.doc_第5页
已阅读5页,还剩37页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

专业好文档三、给出下列程序运行后的输出结果 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; for(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),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; case 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. #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. #include #include struct worker char name15; /姓名 int age; /年龄 float pay; /工资 ; void main() worker x; char *t=liouting; int d=38; float f=493; strcpy(,t); x.age=d; x.pay=f; 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 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 49312. 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; 运行结果: 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; 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出错,退出运行!;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() 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. 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) 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=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: 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=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(, weirong); x.age=45; x.pay=3275; 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) 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; ; 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. #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; 运行结果: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; 运行结果: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) 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; void 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分,共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; int *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); 运行结果:三、写出下列每个程序运行后的输出结果(每小题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() 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 age; /年龄 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; 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; i

温馨提示

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

评论

0/150

提交评论