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

上传人:爱问知识人 文档编号:5065164 上传时间:2020-01-31 格式:DOC 页数:42 大小:272KB
返回 下载 相关 举报
电大C++期末考试复习资料小抄.doc_第1页
第1页 / 共42页
电大C++期末考试复习资料小抄.doc_第2页
第2页 / 共42页
电大C++期末考试复习资料小抄.doc_第3页
第3页 / 共42页
电大C++期末考试复习资料小抄.doc_第4页
第4页 / 共42页
电大C++期末考试复习资料小抄.doc_第5页
第5页 / 共42页
点击查看更多>>
资源描述

《电大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.

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分,共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

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 绩效管理


经营许可证编号:宁ICP备18001539号-1