电大C++期末考试复习资料小抄.doc
《电大C++期末考试复习资料小抄.doc》由会员分享,可在线阅读,更多相关《电大C++期末考试复习资料小抄.doc(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.
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 电大 C+ 期末考试 复习资料
链接地址:https://www.31ppt.com/p-2198422.html