2006年4月全国计算机等级考试二级C++笔试试题及答案
来源:优易学  2010-1-14 16:46:39   【优易学:中国教育考试门户网】   资料下载   IT书店

 

(31)有如下程序:
#include
using namespace std;
class Base
{
private:
void funl() const{cout<<"funl";}
protected:
void fun2() const{cout<<"fun2";}
public:
void fun3() const{cout<<"fun3";}
};
class Derived:protected Base
{
public:
void fun4() const{cout<<"fun4";}
};
int main()
{
Derived obj;
obj.funl(); //①
obj.fun2(); //②
obj.fun3(); //③
obj.fun4(); //④
return 0;
}
其中有语法错误的语句是
A.①②③④
B.①②③
C.②③④
D.①④
(32)有如下程序:
#include
using namespace std;
class Base
{
public:
void funl(){cout<<"Base\n";}
virtual void fun2(){cout<<"Base\n";}
};
class Derived:public Base
{
public:
void funl(){cout<<"Derived\n";}
void fun2(){cout<<"Derived\n";}
};
void f(Base &
B.{b.funl();b.fun2();}&, lt;, /P>
int main()
{
Derived obj;
f(obj);
return 0;
}
执行这个程序的输出结果是
A.Base
B.Base
C.Derived
D.Derived
Base Derived Base Derived
(33)有如下程序:
#include
using namespace std;
class Complex
{
double re, im;
public:
Complex(double r, double i):re(r), im(i){}
double real() const{return re;}
double image() const{return im;}
Complex& operator +=(Complex a)
{
re += a.re;
im += a.im;
return *this;
}
};
ostream &operator<<(ostream& s,const Complex& z)
{
return s<<'('<
}
int main()
{
Complex x(1, -2), y(2, 3);
cout<<(x += y)<
return 0;
}
执行这个程序的输出结果是
A.(1, -2)
B.(2, 3)
C.(3, 5)
D.(3, 1)
(34)有如下程序:
#include
#include
using namespace std;
int main()
{
cout.fill('*');
cout<
return 0;
}
执行这个程序的输出结果是
A.123*OK
B.123*OK**
C.*123OK
D.*123**OK
(35)有如下类声明:
class SAMPLE
{
int n;
public:
SAMPLE (int i = 0): n(i){}
void setvalue(int n0);
};
下列关于setvalue成员函数的实现中,正确的是
A.SAMPLE::setvalue(int n0){n = n0;}
B.void SAMPLE::setvalue(int n0){n = n0;}
C.void setvalue(int n0){n = n0;}
D.setvalue(int n0){n = n0;}

上一页  [1] [2] [3] [4] [5] 下一页

责任编辑:cyth

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训