C++复习题有答案.doc

  1. 1、本文档共9页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
C复习题有答案

分析下列程序的输出结果 1. #include iostream.h class M { int a; public: M(int i=15) {a=i; coutin M\n;} int geta() {return a;} }; void main() { M r1,r2(18); coutoctr1.geta()endl; coutdecr2.geta()endl; } int M int M 17 18 2. #include iostream.h class A { double x; public: A(double i) { x=i; } A operator +(A c) { return A(x*c.x); } double Getx() { return x;} }; void main() { A a(0); a=A(3)+A(4); couta.Getx()+8endl; } 20 3. #include iostream.h class P1 { public: P1(int i) { p1=i; } virtual int fun() { return p1;} private: int p1; }; class P2:public P1 { public: P2(int i,int j):P1(i),p2(j) { } int fun() { return p2;} private: int p2; }; void main() { P1 *pf=new P1(10); P2 *pd=new P2(8,18); P1 b=*pd; coutpf-fun()endl; coutb.fun()endl; cout(*pd).fun()endl; delete pf; delete pd; } 10 18 18 4. #include iostream.h class A { tatic int N; int *a; public: A(int k) { a=new int[N]; for(int j=0;jN;j++) a[j]=j+k; } int geta(int i) { return *(a+i);} static int getN() { return N;} ~A() { coutD\n; delete [] a;} }; void main() { A x(6),y(9); for(int i=0;iA::getN();i++) coutx.geta(i)+y.geta(i)endl; } int A::N=3; 15 17 19 D D 5. #include iostream.h void main() { int a=40; while(--a) { if(a==20) break; if(a%2==0||a%3==0||a%5) continue; couta-1endl; } } 34 24 6. #include iostream.h void main() { int x(5); int fun(int ); int y=fun(x)--; coutyendl; } int w; int fun(int i) { w=i*i; return w; } 25 7. #include iostream.h int y=3; int fun(int,int =2,int c=y); void main() { int a(2),b(3),c(4); int x=fun(a); int y=fun(a,b); int z=fun(a,b,c); coutx+y+zendl; } int fun(int a,int b,int c) { a=b; b=c; c=a; couta+b+cendl; return a+b+c; } 7 8 10 25 8. #include iostream.h class AB { public: AB(int i,int j):b(j) { ab=i+2; coutAB\n; } ~AB() { coutabendl; } friend int fun(AB a); private: static int a; int ab; const i

文档评论(0)

zhuliyan1314 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档