历年全国计算机二级c++考试真题与答案

loading 分享 2026-9-4 下载文档

.

(23)关于动态存储分配,下列说法正确的是

A)new和delete是C++语言中专门用于动态内存分配和释放的函数 B)动态分配的内存空间也可以被初始化

C)当系统内存不够时,会自动回收不再使用的内存单元,因此程序中不必用delete释放内存空间

D)当动态分配内存失败时,系统会立刻崩溃,因此一定要慎用new (24)有以下程序 #include using namespace std; class MyClass { public:

MyClass(int n){number = n;} //拷贝构造函数

MyClass(MyClass &other){ number=other.number;} ~MyClass(){} private: int number; };

MyClass fun(MyClass p) {

MyClass temp(p); return temp; }

int main()

. . .

.

{

MyClass obj1(10), obj2(0); MyClass obj3(obj1); obj2=fun(obj3); return 0; }

程序执行时,MyClass类的拷贝构造函数被调用的次数是 A)5 B)4 C)3 D)2

(25)在公有派生的情况下,派生类中定义的成员函数只能访问原基类的

A)公有成员和私有成员 B)私有成员和保护成员

C)公有成员和保护成员 D)私有成员、保护成员和公有成员 (26)在C++中用来实现运行时多态性的是 A)重载函数 B)析构函数 C)构造函数 D)虚函数

(27)一个类可以同时继承多个类,称为多继承。下列关于多继承和虚基类的表述中,错误的是

A)每个派生类的构造函数都要为虚基类构造函数提供实参 B)多继承时有可能出现对基类成员访问的二义性问题 C)使用虚基类可以解决二义性问题并实现运行时的多态性 D)建立最派生类对象时,虚基类的构造函数会首先被调用 (28)在一个类体的下列声明中,正确的纯虚函数声明是 A) virtual void vf()=0; B) void vf(int)=0; C) virtual int vf(int); D) virtual void vf(int) { } (29)在下面的运算符重载函数的原型中,错误的是 A) Volume operator - (double, double);

. . .

.

B) double Volume::operator- (double); C) Volume Volume: :operator - (Volume); D) Volume operator - (Volume, Volume); (30)下列是模板声明的开始部分,其中正确的是 A) template

B) template C) template D) template (31)执行语句序列

ofstream outfile(\

if(...) cout << \

后,如果文件打开成功显示“OK”,否则就显示“F厶n。”。由此可知,上面if语句的... 处的表达式应是

A )outfile.fail() 或 outfile B )outfile.good() 或 !outfile

C )outfile.good() 或 outfile D )outfile.fail() 或 !outfile

(32)C++流中重载的运算符>>是一个( )

A)用于输出操作的非成员函数 B)用于输入操作的非成员函数 C)用于输出操作的成员函数 D)用于输入操作的成员函数 (33)有以下类定义 class Point { public:

Point(int x = 0, int y = 0) { _.x = x; _.y = y; } void Move(int xOff, int yOff)

. . .

.

{ _x += xOff; _.y += yOff; } void Print() const

{ cout << '(' << _x << ',' << _y << ')' << endl; } private:

int _x, _y; };

下列语句中会发生编译错误的是 A) Point pt; pt.Print(); B) const Point pt; pt.Print(); C) Point pt; pt.Move(l, 2); D) const Point pt; pt.Move(l, 2); (34)有以下类定义 class MyClass { private: int id; char gender, char *phone; public:

MyClass():id(0),gender('#'),phone(NULL) { } MyClass(int no, char ge='#', char *ph= NULl.) { id=no;gende=ge;phone=ph; } };

下列类对象定义语句中错误的是 A) MyClass myObj;

B) MyClass myObj(11, \

. . .

.

C) MyClass myObj(12, 'm'); D) MyClass myObj(12); (35)有以下程序 #include 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() {

Complex a = Complex(l, 1) + Complex(5);

cout << a.real() << '+' << a.imag() <<'i' << endl; return 0; }

程序执行后的输出结果是

A) 6+6i B) 6+1i C) 1+6i D) 1+1i 二、填空题(每空2分,共30分)

请将每一个空的正确答案写在答题卡[1]-[15]序号的横线上,答

. . .


历年全国计算机二级c++考试真题与答案.doc 将本文的Word文档下载到电脑
搜索更多关于: 历年全国计算机二级c++考试真题与答案 的文档
相关推荐
相关阅读