2013年9月全国计算机等级《二级C++》考前冲刺试卷三

如果您发现本试卷没有包含本套题的全部小题,请尝试在页面顶部本站内搜索框搜索相关题目,一般都能找到。
1

使用VC++6.0打开考生文件夹下的源程序文件3.cpp,其中定义了用于表示矩形的CRect类,但类CRect的定义并不完整。请按要求完成下列操作,将类CRect的定义补充完整。

(1)定义私有数据成员leftPoint、topPoint、rightPoint、bottomPoint,分别用于表示矩形左上角及右下角的点的坐标,它们都是double型的数据。请在注释1之后添加适当的语句。

(2)完成默认构造函数CRect的定义,指定默认实参为0,它们都是double型的数据。请在注释2之后添加适当的语句。

(3)定义函数体为空的析构函数。请在注释3之后添加适当的语句。

(4)在main函数中定义GReet类的实例rect2,并把re-

ct1的值赋给rect2。请在注释4之后添加适当的语句。

注意:除在指定位置添加语句之外,不要改动程序中的其他内容。

试题程序:

#include

classCRect

{

private:

//********1********

public:

//********2********

//********3********

voidSetPoints(double,double,double,double);

voidSetLeftPoint(doublem){leftPoint=m;}

voidSetRightPoint(doublem){rightPoint=m;}

voidSetTopPoint(doublem){topPoint=m;}

voidSetBottomPoint(doublem){bottomPoint=m;}

voidDisplay();

};

CReet::CRect(double1,doublet,doubler,doubleb)

{

leftPoint=1;topPoint=t;

rightPoint=r;bottomPoint=b;

}

voidCRect::Setpoints(double1,doublet,doubler,doubleb)

{

leftPoint=1;topPoint=t;

rightPoint=n;bottomPoint=b;

}

voidCRect::Display()

{

cout<<"left-toppointis("<

Point<<")"<<'\n';

cout<<"right-bottompointis("<

<}

voidmain()

{

CRectrect0;

rect0.Display();

rect0.SetPoints(20,20.6,30,40);

rect0.Display();

CRectrectl(0,0,150,150);

rect1.SetTopPoint(10.5);

rect1.SetLeftPoint(10.5);

//********4******** rect2.Display( );}

4

若目前D盘根目录下并不存在test.txt文件,则下列打开文件方式不会自动创建test,txt文件的是(  )。

  • A.ifstreamfin;fin.open("d:\\test.txt",iso_base::in);
  • B.fstreamfi0;ri0.open("d:\\test.txt",is0_base::out);
  • C.ofstream。fort;lout.open("d:\\test.txt",ios_base::out);
  • D.ofstreamfout;fout.open("d:\\test.txt",is0_base::app);
5

数据库DB、数据库系统DBS、数据库管理系统DBMS之间的关系是(  )。

  • A.DB包括DBS和DBMS
  • B.DBMS包括DB和DBS
  • C.DBS包括DB和DBMS
  • D.没有任务关系
6

下列是重载为非成员函数的运算符函数原型,其中错误的是(  )。

  • A.Fractionoperator+(Fraction,Fraction);
  • B.Fractionoperator-(Fraction);
  • C.Fraction&operator=(Fraction&,Fraction);
  • D.Fraction&operator+=(Fraction&,Fraction):
7

下列关于函数模板的描述中,正确的是(  )。

  • A.函数模板是一个实例函数
  • B.使用函数模板定义的函数没有返回类型
  • C.函数模板的类型参数与函数的参数相同
  • D.通过使用不同的类型参数,可以从函数模板得到不同的实例函数
8

若有如下程序:

#include

usingnamespacestd;

classTestClassl

{

private:

inta;

public:

TestClassl(inti)

{

  • a=i:&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;voiddisp(  )&nbsp;&nbsp;&nbsp;&nbsp;{
  • cout<}&nbsp;&nbsp;&nbsp;&nbsp;};
  • classTestClass2&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;private:
  • intb:&nbsp;&nbsp;&nbsp;&nbsp;public:&nbsp;&nbsp;&nbsp;&nbsp;TestClass2(intj)&nbsp;&nbsp;&nbsp;&nbsp;{
  • b=j;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;voiddisp()&nbsp;&nbsp;&nbsp;&nbsp;{
  • cout<}&nbsp;&nbsp;&nbsp;&nbsp;};
  • classTestClass3:publicTestClass2,publicTestClassl&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;private:
  • intc;&nbsp;&nbsp;&nbsp;&nbsp;public:&nbsp;&nbsp;&nbsp;&nbsp;TestClass3(intk):TestClass1(k-2),TestClass2(k+2)&nbsp;&nbsp;&nbsp;&nbsp;{
  • c=k:&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;voiddisp()&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;TestClasssl::disp();&nbsp;&nbsp;&nbsp;&nbsp;TestClasss2::disp();
  • cout<<c<<endl;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;};
9

下列各类函数中,不是类的成员函数的是(  )。

  • A.构造函数
  • B.抽象类
  • C.派生类
  • D.以上都不对
10

下面关于break语句的描述中,不正确的是(  )。

  • A.break可以用于循环体内
  • B.break语句可以在for循环语句中出现多次
  • C.break语句可以在switch语句中出现多次
  • D.break语句可用于if条件判断语句内
11

将运算符“+”重载为非成员函数,下列原型声明中,错误的是(  )。

  • A.MyClockoperator+(MyClock,long);
  • B.MyClockoperator+(MyClock,MyCloek);
  • C.MyCloekoperator+(long,long);
  • D.MyClockoperator+(long,MyCloek):
12

下列关于栈叙述正确的是(  )。

  • A.栈顶元素最先能被删除
  • B.栈顶元素最后才能被删除
  • C.栈底元素永远不能被删除
  • D.以上三种说法都不对
13

最简单的交换排序方法是(  )。

  • A.快速排序
  • B.选择排序
  • C.堆排序
  • D.冒泡排序
16

下列代码段声明了3个类:

classPerson{);

classStudent:publicPerson{};

classUndergraduate:Student{);

下列关于这些类之间关系的描述中,错误的是(  )。

  • A.类Person是类Undergraduate的基类
  • B.类Undergraduate从类Student公有继承
  • C.类Student是类Person的派生类
  • D.类Undergraduate是类Person的派生类
17

下列选项中不属于软件生命周期开发阶段任务的是(  )。

  • A.软件测试
  • B.概要设计
  • C.软件维护
  • D.详细设计
18

下列关于运算符重载的描述中,正确的是(  )。

  • A.运算符重载为成员函数时,若参数表中无参数,重载的是一元运算符
  • B.一元运算符只能作为成员函数重载
  • C.二元运算符重载为非成员函数时,参数表中有一个参数
  • D.C++中可以重载所有的运算符
20

下列各组类型声明符中,含义相同的一组是(  )。

  • A.unsignedlongint和long
  • B.signedshort和short
  • C.unsignedshort和short
  • D.shortint和int
21

类模板templateclassX{…},其中友元函数f对特定类型T(如int),使函数f(x)成为x模板类的友元,则其说明为(  )。

  • A.friendvoidf();
  • B.friendvoidf(x<T>);
  • C.friendvoidA::f();
  • D.friendvoidC<T>::f(x<T>);
24

下列枚举类型的定义中,包含枚举值3的是(  )。

  • A.enumtest{RED,YELLOW,BLUE,BLACK};
  • B.enumtest{RED,YELLOW=4,BLUE,BLACK);
  • C.enumtest{RED=-1,YELLOW,BLUE,BLACK};
  • D.enumtest{RED,YELLOW=6,BLUE,BLACK);
25

下列语句都是程序运行时的第1条输出语句,其中一条语句的输出效果与其他3条语句不同,该语句是(  )。

  • A.cout<<internal<<12345;
  • B.tout<<left<<12345;
  • C.cout<<right<<12345;
  • D.tout<<setw(6)<<12345;
28

下列关于纯虚函数与抽象类的描述巾,错误的是(  )。

  • A.纯虚函数是一种特殊的虚函数,它没有具体的实现
  • B.抽象类是指具有纯虚函数的类
  • C.一个基类声明了纯虚函数,该基类的派生类一定不是抽象类
  • D.抽象类只能作为基类来使用,其纯虚函数的实现由派生类给出
29

以下不能正确创建输出文件对黎并使其与磁盘文件相关联的语句是(  )。

  • A.ofstreammyfile;myfile.open("d:ofile.txt");
  • B.ofstream*myfile=newofstream;myfile->open("d:ofile.txt”);
  • C.ofstreammyfile("d:ofile.txt");
  • D.ofstream*myfile=new("d:ofile.txt");
30

对于长度为n的线性表,在最坏情况下,下列各排序法所对应的比较次数中正确的是(  )。

  • A.冒泡排序为n/2
  • B.冒泡排序为n
  • C.快速排序为n
  • D.快速排序为n(n-1)/2
38

下列关于虚基类的描述,错误的是(  )。

  • A.设置虚基类的目的是为了消除二义性
  • B.虚基类的构造函数在非虚基类之后调用
  • C.若同一层中包含多个虚基类,这些虚基类的构造函数按它们说明的次序调用
  • D.若虚基类由非虚基类派生而来,则仍然先调用基类构造函数,再调用派生类的构造函数
40

设有定义charstr[80];以下不能将输入数据first\nsecond\n读取到数组str中的语句是(  )。

  • A.cin.get(str,strlen(str));
  • B.cin.getline(str,strlen(str));
  • C.cin>>str;
  • D.cin.read(str,strlen(str));
41

下列叙述中正确的是(  )。

  • A.全局变量的作用域一定比局部变量的作用域范围大
  • B.静态类别变量的生存期贯穿于整个程序的运行期间
  • C.函数的形参都属于全局变量
  • D.未在定义语句中赋初值的aut0变量和static变量的初值都是随机值
42

下列叙述中正确的是(  )。

  • A.软件测试应该由程序开发者来完成
  • B.程序经调试后一般不需要再测试
  • C.软件维护只包括对程序代码的维护
  • D.以上三种说法都不对