C++考题2Word文档下载推荐.docx

上传人:b****7 文档编号:22513765 上传时间:2023-02-04 格式:DOCX 页数:25 大小:18.72KB
下载 相关 举报
C++考题2Word文档下载推荐.docx_第1页
第1页 / 共25页
C++考题2Word文档下载推荐.docx_第2页
第2页 / 共25页
C++考题2Word文档下载推荐.docx_第3页
第3页 / 共25页
C++考题2Word文档下载推荐.docx_第4页
第4页 / 共25页
C++考题2Word文档下载推荐.docx_第5页
第5页 / 共25页
点击查看更多>>
下载资源
资源描述

C++考题2Word文档下载推荐.docx

《C++考题2Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《C++考题2Word文档下载推荐.docx(25页珍藏版)》请在冰豆网上搜索。

C++考题2Word文档下载推荐.docx

(B)

Public:

Csample(intval);

(C)

~Csample();

(D)

};

6、关于成员函数的下述描述中,是错误的。

A.成员函数可以设置参数的缺省值。

B.成员函数一定是内联函数。

C.成员函数可以重载。

D.成员函数可以是静态的。

7、关于缺省构造函数的下述描述中,是错误的。

A.如果没有定义构造函数或缺省构造函数,编译器会自动生成缺省构造函数。

B.如果类有缺省构造函数,则可以不传递参数而定义类对象。

C.缺省构造函数不对类对象数据成员赋初值。

D.如果定义了类的构造函数,则编译器不再生成缺省构造函数。

8、下面对成员函数f()的调用A、B、C、D中,不是动态联编的为

#include"

iostream.h"

classA

public:

virtualvoidf()

{cout<

<

"

A:

:

f()called"

endl;

}

voidg()

{f();

}---------------------------------------(A)

classB:

publicA

public:

virtualvoidf()

B:

voidmain()

A*pa=newB();

pa->

f();

-----------------------------------------(B)

Bb;

b.f();

-------------------------------------------(C)

A&

a=b;

a.f();

-------------------------------------------(D)

Aa2;

a2.g();

deletepa;

9、以下哪种构造函数不是单参数构造函数?

A.复制构造函数

B.只有第一个参数,其它参数为缺省的构造函数。

C.缺省构造函数。

D.转换构造函数。

10、已知:

print()函数是一个类的常成员函数,它无返回值,下列表示中,是正确的。

A.voidprint()const;

B.constvoidprint();

C.voidconstprint;

D.voidprint(const);

11、下面程序中对成员函数的访问中,错误的是。

#include"

voidf1()

{

cout<

f1()called"

}

protectedA

voidf2()

f2()called"

classC:

privateB

voidf3()

f1();

---------------------------------------------(A)

f3called"

Cc;

c.f3();

-----------------------------------------------(B)

c.f2();

------------------------------------------------(C)

b.f2();

-------------------------------------------------(D)

12、派生类的构造函数的成员初始化列表中,不能包含。

A.基类的构造函数。

B.派生类中对象成员的初始化。

C.基类中对象成员的初始化。

D.派生类中一般数据成员的初始化。

13、有关虚基类的描述中错误的是。

A.最派生类构造函数中的虚基类构造函数会被调用。

B.虚基类可以消除二义性。

C.每个派生类构造函数成员初始化器表中都包含有对虚基类构造函数的调用,故虚基类构造函数会被调用多次。

D.虚基类只有一个。

14、关于虚析构函数的下述描述中,是错误的。

A.基类中析构函数为虚析构函数,则派生类中的析构函数也为虚析构函数。

B.虚析构函数能保证delete运算符有效的释放基类及派生类对象。

C.将析构函数定义为虚析构函数是因为类中有虚函数。

D.虚析构函数并不能实现动态联编。

15、关于纯虚函数和抽象类的描述中,是错误的。

A.纯虚函数没有函数体。

B.抽象类及其派生类都可以定义对象。

C.若某个成员函数为纯虚函数,则该类为抽象类。

D.抽象类通常在类结构的顶层。

二、分析下列程序的输出结果(每小题3分,共30分)

1、#include"

string.h"

A(char*st);

~A();

private:

charstring[50];

A(char*st)

strcpy(string,st);

cout<

string<

~A()

voidfun()

AFunobj("

fun"

);

staticAStaobj("

sta"

AGlobobj("

Glob"

AMainobj("

Main"

cout<

fun();

2、

#include<

iostream.h>

classctest

staticintcount;

ctest()

++count;

~ctest()

--count;

staticintgetcount()

returncount;

intctest:

count=5;

ctest:

getcount()

objectexist\n"

;

ctesttest1;

ctest*ptest2=newctest;

deleteptest2;

3、

#include"

A(intj){a=j;

intfun(intb)

{return(a+b*c);

intc;

inta;

Ax(8);

intA:

*pc;

pc=&

c;

x.*pc=5;

int(A:

*pfun)(int);

pfun=A:

fun;

A*p=&

x;

(p->

*pfun)(5);

4、

A()

{a=0;

A'

sD.C.\n"

A(inti)

{a=i;

sC.\n"

~A()

{cout<

sD.\n"

B()

{b=0;

B'

sD.C-\n"

B(inti,intj,intk)

A(i),aa(j)

{b=k;

sC-\n"

}

~B()

sD.-\n"

intb;

Aaa;

{

B*pb=newB[2];

pb[0]=B(1,2,3);

pb[1]=B();

delete[]pb;

5、

A(constchar*s)

s<

~A(){}

virtualpublicA

B(constchar*s1,constchar*s2)

A(s1)

s2<

C(constchar*s1,constchar*s2)

classD:

publicC,publicB

D(constchar*s1,constchar*s2,

constchar*s3,constchar*s4)

B(s1,s3),C(s1,s2),A(s4)

s1<

D*ptr=newD("

A"

"

B"

C"

D"

deleteptr;

6、

virtualvoidact1();

voidact2();

voidact3(){act1();

act2();

voidA:

act1()

act1()called"

act2()

act2()called"

{public:

voidact1();

voidB:

b.act3();

b.act1();

7、

A(){}

f()called\n"

voidh()

h()called"

B(){f();

publicB

C(){}

C:

voidg(A*aa)

aa->

h();

C*cp=newC;

g(cp);

deletecp;

8、

A(inti,intj){a=i,b=j;

voidmove(intx,inty)

{a+=x;

b+=y;

voidshow()

a<

b<

inta,b;

B(inti,intj,intk,intl)

A(i,j),x(k),y(l)

{}

x<

y<

voidfun(){move(3,5);

voidf1(){A:

show();

intx,y;

Ae(1,2);

e.show();

Bd(3,4,5,6);

d.fun();

d.A:

d.B:

d.f1();

9、

virtual~A()

~A()called\n"

B(inti)

{buf=newchar[i];

delete[]buf;

~B()called\n"

char*buf;

voidfun(A*a)

{deletea;

A*a=newB(15);

fun(a);

10、

A(inti=1)

{m=i;

CON.called"

m<

voidprint()

DES.called"

intm;

constintN=8;

Amy;

my.print();

my=N;

三、根据题义填空(每空一分,共15分)

1、下面程序中非缺省构造函数为复制构造函数。

classcmessage

char*buffer;

cmessage()

{buffer=newchar('

\0'

cmessage(

(1))

(2);

(3);

~cmessage()

{deletebuffer;

voiddisplay()

buffer<

'

\n'

voidset(char*string)

{delete[]buffer;

buffer=newchar[strlen(string)+1];

strcpy(buffer,string);

voidmain()

{cmessagemessage1;

message1.set("

hello"

cmessagemessage2((4));

cmessagemessage3=(5);

2、下面程序设类B1中b1只能被本类以及派生类函数访问,类B2中b2只能被本类函数访问,函数g()可以在类以外函数中被访问,main()函数中变量m为c1经类B1继承的a及经B2继承的a之和。

inta;

classB1:

(6):

intb1;

classB2:

(7):

intb2;

(8):

intg()

b2<

b1;

publicB1,publicB2

Cc1;

intm;

m=(9)+(10);

3、下面程序将++运算符重载为成员函数。

#include”iostream.h”

classcounter

counter(){v=0;

(11)operater++(12)

v++;

return(13);

(14)operator++(15)

coutert;

t.v=v++;

returnt;

voidprint()

v<

unsignedv;

countc;

for(intj=0;

j<

8;

j++)

c++;

c.print();

for(j=0;

++c;

四、程序设计(25分)

1.编写转换构造函数,简化下面程序中为不同操作数编写的运算符函数(10分)

classCcurrency

longdollars;

intcents;

Ccurrency()

dollars=cents=0;

Ccurrency(longdol,intcen)

dollars=dol+cen/100;

cents=cen%100;

Ccurrencyoperator+(constCcurrency&

curr)

returnCcurrency(dollars+curr.dollars,cents+curr.cents);

Ccurrencyoperator+(longdol)

returnCcurrency(dollars+dol,cents);

friendCcurrencyoperator+(longdol,constCcurrency&

curr);

Ccurrencyoperator+(longdol,constCcurrency&

returnCcurrency(dol+curr.dollars,curr.cents);

Ccurrencyadvertising(235,42);

Ccurrencyrent(823,68);

CcurrencyOverhead;

Overhead=advertising+rent;

Overhead=Overhead+100;

Overhead=100+Overhead;

2、已知类的层次结构为如下单继承:

shape

circle

cylinder

其中顶层shape为抽象类,circle为圆形类,其可求出圆形的面积,cylinder为圆柱体的类,其可求出圆柱体的体积。

编写以上类的层次结构,求圆形面积及圆柱体体积。

设半径r=5,,圆柱体高h=10,计算面积及体积函数为value(),求出面积及体积并输出。

(15分)

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 考试认证 > 交规考试

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1