文档介绍:20XX年4至20XX年3月计算机二级C++真题及答案全
20XX年4月计算机等级考试C考试及答案
一选择题每小题2分共70分
下列各题ABCD四个选项中只有一个选项是正确的请函数必须在派生类中重新实现
24下列运算符中不能被重载的是
A&& B C D
25下列函数模板的定义中合法的是
A template TabsT x return x 0 – x x
Btemplate class TabsTx retumx 0 -xx
Ctemplate T absT x retum x 0 -xx
Dtemplate T absT x returm x 0 -xx
26在语句cin data中cin是
AC的关键字 B类名
C对象名 D函数名
27有如下程序
include
using namespace std
class test
private
int a
public
test cout constructor endl
testint a cout a endl
testconst test&_test
a _testa
cout copy constructor endl
test cout destructor endl
int main
test A3
return0
运行时输出的结果是
A3
Bconstructor
destruclor
Ccopy constructor
D3
dstructor destruclor
28若有如下类声明
class My Class
public
MyClass cout 1
执行下列语句
MyClass ab[2]P[2]
以后程序的输出结果是
A11 B111 C1111 D11111
29有如下程序
include
using namespace std
class point
public
static int number
public
point number
~point number-
imt pointnumber 0
void main
pointptr
printAB
pointptr_point new point 3
ptr ptr_point
pointC
cout pointnumber endl
delete[]ptr
运行时输出的结果是
A3 B4 C6 D7
30如果不使用多态机制那么通过基类的指针虽然可以指向派生类对象但是只能访问从基类继承的成员有如下程序没有使用多态机制
include
using namespace std
class Base
int ab
public
Baceint x int y a x b y
Void show cout a b endl
clsaa Derivedpublic Base
int c d
public
Derivedint xint yint zint mBasexy c z d m
Void show cout c d endl
int main
Base B15050pb
Derived DI10203040
Pb &D1
Pb- show
Return 0
运行时输出的结果是
A1020 B3040 C2030 D5050
31有如下程序
include
using namespace std
class A
public
Aint i x i
Void sispa cout x
Private
int x
class BpublicA
public
Bint iAi 10 x i
voud dispb dispacout x endl
Private
Int x
int main
B b2
bdispb
retum 0
运行时输出的结果是
A102 B1210 C122 D22
32虚函数支持多态调用一个基类的指针可以指向派生类的对象而且通过这样的指针调用虚函数时被调用的是指针所指的实际对象的虚函数而非虚函数不支持多态调用有如下程序
include
using namespace std
class Base
public
virtual v