2003级C++面向对象程序设计试题B-计算机学院2004年冬天.docVIP

2003级C++面向对象程序设计试题B-计算机学院2004年冬天.doc

  1. 1、本文档共6页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
  5. 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
  6. 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们
  7. 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
  8. 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
一、[25分,每小题5分] 指明下列各程序中存在的不符合C++语言规范之处(每题一处),说明你的理由或依据。解答方式可参考下面例子。 例子程序: #include iostream.h class A { protected: void f( ) { cout A::f( ) endl;} }; void main( ) { A a; a.f( ); } 对左边例子程序可以解答如下: 成员函数f被说明成protected,这与main函数中对它的使用:a.f( )语句不符。理由是:一个类中protected访问权限下的成员除了可用于实现该类、实现该类的派生类或后裔类、实现友员外,不能被使用。 (1) #include iostream.h class B { public: virtual void f( ) const { cout B::f( ) endl; } B(int int1,int int2) : j(int2), i(int1) { } private: int i; int j; }; class D: public B { public: D(int anInt) : i(anInt) { } void f( ) const { cout D::f( ) endl; } private: int i; }; void main( ) { D d; d.f( ); } (2) class A { public: A* f( ) { pA = new A; return pA; } ~A( ) { if (pA) delete pA; } static A* g( ) { return this; } private: int i; static A* pA; }; A* A::pA = 0; void main( ) { A a; A* p = a.f( ); A* q = a.g( ); } (3) #include iostream.h class B; class A { public: A(int anInt=0):i(anInt) { } A(const B aB); int getI( ) const { return i; } private: int i; }; class B { public: B(int int1=0, int int2=0): i(int1),j(int2) { } int getI( ) const { return i; } int getJ( ) const { return j; } operator A( ) { int k = (ij)?i:j; return A(k); } private: int i; int j; }; A::A(const B aB) { if (aB.getI( ) aB.getJ( )) i = aB.getI( ); else i = aB.getJ( ); } void main( ) { B b(10,20); A a(b); cout a.getI( ) endl; } (4) #include iostream.h class A { public: A(int anInt=0): a(anInt) { } void f( ) { cout A::f( ) endl; } void g( ) { if (i0) a.f( ); else cout A::g( ) endl; } private: int i; A a; }; void main( ) { A a1(100); a1.g( ); A a2(-10); a2.g( ); } (5) #include iostream.h class Complex { public: Complex(float r=0.0,float i=0.0) : rPart(r), iPart(i) { } private: float rPart; float iPart; }; void main( ) { Complex c1; Complex c2(3.14); Complex c3(c2); c1 = c2; cout c1 c2 c3 endl; } 二、[20分,每小题10分] 分别写出下列两个程序的运行结果. (1) #include iostream.h class A { p

您可能关注的文档

文档评论(0)

1243595614 + 关注
实名认证
文档贡献者

文档有任何问题,请私信留言,会第一时间解决。

版权声明书
用户编号:7043023136000000

1亿VIP精品文档

相关文档