微信搜索关注"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.232B.231C.222D.221 参考答案: D ----------------------------------------31、已知p是一个指向类Sample数据成员m的指针,s是类Sample 的一个对象。如果要给 m赋值为5,( )是正确的。 A..=5B.->=5C..*=5D.*.=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.taticB.cotC.mutaleD.不需要填入内容 参考答案: 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.xyB.yxC.xD.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
|