TOP

2010计算机等级考试二级(C++)笔试151(五)
2011-02-06 07:34:12 来源: 作者:[标签:作者] 【 】 浏览:882次 评论:0
微信搜索关注"91考试网"公众号,领30元,获取公务员、事业编、教师等考试资料40G!
友元函数

参考答案: A

----------------------------------------

30、 有如下程序: #include <iostream> using namespace std; class Obj { static int i; public: Obj(){i++;} ~Obj(){i--;} static int getVal(){return i;} }; int Obj::i=0; void f(){Obj ob2; cout<<ob2.getVal(); } int main(){ Obj ob1; f(); Obj *ob3=new Obj; cout<<ob3->getVal(); delete ob3; cout<<Obj:: getVal(); return (); } 程序的输出结果是( )。

A.232

B.231

C.222

D.221

参考答案: D

----------------------------------------

31、已知p是一个指向类Sample数据成员m的指针,s是类Sample 的一个对象。如果要给 m赋值为5,( )是正确的。

A..=5

B.->=5

C..*=5

D.*.=5

参考答案: C

----------------------------------------

32、 有如下类的定义,下划线处的语句是( )。 class MyClass { _______________ int x, y; Public: MyClass (int a=0,int b=0) { x=a; y=b; } static void change() { y-=10; y-=10; } };

A.tatic

B.cot

C.mutale

D.不需要填入内容

参考答案: A

----------------------------------------

33、下列是重载乘法运算符的函数原型声明,其中错误的是 ( )。

A.MyCla oerator * (doule, doule)

B.MyCla oerator * (doule, MyCla)

C.MyCla oerator * (MyCla, doule)

D.MyCla oerator * (MyCla, MyCla)

参考答案: A

----------------------------------------

34、 有如下程序: #include <iostream> using namespace std; class Base { private: char c; public: Base(char n):c(n){} ~Base() { cout<<c; } }; class Derived: public Base { private: char c; public: Derived(char n):Base(n+1),c(n){} ~Derived() { cout<<c; } }; int main() { Derived obj(''''x''''); return 0; } 执行上面的程序将输出( )。

A.xy

B.yx

C.x

D.y

参考答案: A

----------------------------------------

35、 有以下程序 #include <iostream> using namespace std; class Complex { public: Complex(double r=0,double i=0):re(r),im(i){} double real() const {return re;} double imag() const { return im; } Complex operator+(Complex c) const {return Complex(re+c.re,im+c.im);} private: double re,im; }; int main() { Co
Tags:计算机二级考试试题 计算机二级考试真题 责任编辑:w48225117
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇2010计算机等级考试二级(C++)笔.. 下一篇2010计算机等级考试二级(C++)笔..

相关栏目

最新文章

推荐文章

网站客服QQ: 960335752 - 14613519 - 48225117