我爱学习网 52xx.cn我爱学习网菜单按钮
  • 搜索
当前位置:首页 > 阅读 > 计算机等级考试

计算机二级

发布时间:2021-02-03 栏目:阅读 投稿:背后的夏天

我爱学习网为考生们整理了“2018年9月计算机二级考试C++考前基础习题”,希望有所帮助,想了解更多考试资讯,请关注小编的及时更新哦。

2018年9月计算机二级考试C++考前基础习题二

1.下列控制格式输入输出的操作符中,能够设置浮点数精度的是()。

A.setprecision

B.setw

C.setfill

D.showpoint

2.下列程序段中包含4个函数,其中具有隐含this指针的是()。

intfunl();

classTest{

public:

intfun2();

friendintfun3();

staticintfun4();

};

A.funl

B.fun2

C.fun3

D.fun4

3.有如下程序

#include

usingnamespacestd;

classTest(

public:

Test(){}

Test(constTest8Lt){cout<<1;}

};

Testfun(Test&u){Testt=U;returnt;}

intmain(){Testx,y;x=fun(y);return0;}

运行这个程序输出结果是()。

A.无输出

B.1

C.1l

D.111

4.有如下程序

#include

usingnamespacestd;

classA{

public:

A(inti=O):rl(i){}

voidprint(){cout<<’E’

voidprint(intx){cout<<’P’<-’;}

private:

intr1;

};

intmain(){

Aal:

constAa2(4);

a1.print(2);

a2.print();

return0;

}

运行时的输出结果是()。

A.P8一E4

B.P8一C16一

C.P0一E4一

D.P0一C16—

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

classPerson{);

classStudent:publicPerson{};

classUndergraduate:Student{);

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

A.类Person是类Undergraduate的基类

B.类Undergraduate从类Student公有继承

C.类Student是类Person的派生类

D.类Undergraduate是类Person的派生类

6.有如下程序

#include

Usingnamespacestd;

classBase{

public:

Base(intx=O):valB(x){cout<~Base(){cout

intvalB:

};

classDerived:publicBase{

public:

Derived(intX=0,inty=0):Base(x),valD(y)(cout<~Derived(){cout

intvalD;

};

intmain(){

Derivedobj12(2,3);

return0;

}

运行时的输出结果是()。

A.2332

B.2323

C.3232

D.3223

7.下面是类Shape的定义:

classShape{

public:

virtualvoidDraw()=0;

}

下列关于Shape类的描述中,正确的是()。

A.类Shape是虚基类

B.类Shape是抽象类

C.类Shape中的Draw函数声明有误

D.语句“ShapeS;”能够建立Shape的一个对象S

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

A.MyClockoperator+(MyClock,long);

B.MyClockoperator+(MyClock,MyCloek);

C.MyCloekoperator+(long,long);

D.MyClockoperator+(long,MyCloek):

9.打开文件时可单独或组合使用下列文件打开模式:

①ios_base::aop

②ios_base::binary

③ios_base::

④ios_base::out

若要以二进制读方式打开一个文件,需使用的文件打开模式为()。

A.①③

B.①④

C.②③

D.②④

10.有如下程序

#include

usingnamespacestd;

classB{

public:

B(intxx):x(xx){++count;x+=10;}

virtualvoidshow()const

{cout

staticintcount;

private:

intx;

};

classD:publicB{

public:

D(intxx,intyy):B(XX),y(yy){++count;y+=

100;)

virtualvoidshow()const

{cout

inty;

};

intB::count==0;

intmain(){

B*ptr=newD(10,20);

ptr->show();

deleteptr;

return0;

}

运行时的输出结果是()。

A.1_120

B.2_120

C.1_20

D.2_20

参考答案:

1.A。【解析】setprecision(int)是设置浮点数的精度,setw(intn)是设置输入输出宽度,setfill(charc)设置填充字符,showpoint即使小数部分为0,也输出以及其后的无效数据0。

2.B。【解析】this指针是成员函数所属对象的指针,是指向类对象的地址,是一个隐含的指针,隐含于每个类的非静态成员函数中。funl是外部函数,fun3是友元函数,fun4是静态成员函数,故选B。

3.C。【解析】本题调用了fun函数

4.D。

5.B。【解析】类Undergraduate从类Student私有继承继承方式缺省则默认是private。

6.A。【解析】本题使用析构函数

7.B。【解析】抽象类是类中至少有一个纯虚函数,抽象类是用来被继承的,即是用来生成派生类,它本身不能生成实例。

8.C。【解析】非成员函数一般都是友元函数,相比成员函数第一个操作数是对象本身以thiS指针的形式隐含在参数列表中,非成员函数调用必须显式的列出参数;选项C中没有MyClock类型,故选C。

9.D。【解析】ios_base::binary是作为二进制文件打开,ios_base::out是为输出打开,故选D。

10.B。【解析】本题考查了类的继承继承有3种方式,public公有、private私有和protected保护,本题都涉及了。本题中类D公有继承类B。在类B中又定义了虚函数,并且有保护类静态类型count及私有变量x。主函数中调用类D,类D又继承了类B,经过系统及调用,本题最终结果为2_120。

我爱学习网栏目推荐

相关推荐:

2017年计算机一级考试高频考点(一)

2017年12月的计算机等级考试

贵州计算机等级考试

计算机二级

计算机一级