第四套模拟试题.docx

上传人:b****4 文档编号:3812736 上传时间:2023-05-06 格式:DOCX 页数:22 大小:26.61KB
下载 相关 举报
第四套模拟试题.docx_第1页
第1页 / 共22页
第四套模拟试题.docx_第2页
第2页 / 共22页
第四套模拟试题.docx_第3页
第3页 / 共22页
第四套模拟试题.docx_第4页
第4页 / 共22页
第四套模拟试题.docx_第5页
第5页 / 共22页
第四套模拟试题.docx_第6页
第6页 / 共22页
第四套模拟试题.docx_第7页
第7页 / 共22页
第四套模拟试题.docx_第8页
第8页 / 共22页
第四套模拟试题.docx_第9页
第9页 / 共22页
第四套模拟试题.docx_第10页
第10页 / 共22页
第四套模拟试题.docx_第11页
第11页 / 共22页
第四套模拟试题.docx_第12页
第12页 / 共22页
第四套模拟试题.docx_第13页
第13页 / 共22页
第四套模拟试题.docx_第14页
第14页 / 共22页
第四套模拟试题.docx_第15页
第15页 / 共22页
第四套模拟试题.docx_第16页
第16页 / 共22页
第四套模拟试题.docx_第17页
第17页 / 共22页
第四套模拟试题.docx_第18页
第18页 / 共22页
第四套模拟试题.docx_第19页
第19页 / 共22页
第四套模拟试题.docx_第20页
第20页 / 共22页
亲,该文档总共22页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

第四套模拟试题.docx

《第四套模拟试题.docx》由会员分享,可在线阅读,更多相关《第四套模拟试题.docx(22页珍藏版)》请在冰点文库上搜索。

第四套模拟试题.docx

第四套模拟试题

专业

班级

学号

姓名

 

教研室主任

(签字)

 

学院院长(系主任)

(签字)

课程TheC++ProgrammingLanguage

课程性质(√必修□专业限选□任选)考试方式(√闭卷□开卷)

得分

PartI、Selection(totalquestions60points,2pointsperquestionforthefirst20questionsand4pointsperquestionforthelast5questions.)

1.Suppose:

voidmain(){

intx=5,y=7;

x=x+y;

y=x-y;

x=x-y;

cout<<”x=”<

}

Whichofthefollowingiscorrectoutput?

A.x=7y=5B.x=5y=7C.x=7y=7D.x=5y=5

2.Suppose:

intx=1,y=1,z=1;

--x&&++y&&++z;

cout<

Whichofthefollowingiscorrectoutput?

A.022B.011C.122D.121

3.Whichofthefollowingiscorrectfunctiondeclaration?

A.intfun(x,y)B.doublefun(intx;inty)

C.voidfun(void)D.doublefun(intx,y)

4.Suppose:

intk;

inta[3][3]={1,2,3,4,5,6,7,8,9};

for(k=0;k<3;k++)cout<

Whichofthefollowingiscorrectoutput?

A.147B.159C.369D.357

5.Suppose:

constchar*p=”ABC”;

Whichofthefollowingiscorrect?

A.p=NULLB.char*q=p;C.*p=’\0’D.p[0]=’B’

6.Whichofthefollowingiscorrectoutput?

int&max(int&x,int&y){return(x>y)?

x:

y;}

voidmain(){

intm

(2),n(3);

max(m,n)--;

cout<

}

A.23B.32C.33D.22

题号

总分

得分

7.Suppose:

inti=100;

intfun(){

staticinti=10;

return++i;

}

voidmain(){

fun();

fun();

cout<

}

Whichofthefollowingiscorrectoutput?

A.13,100B.12,100C.11,100D.10,100

8.Whichofthefollowingcodemarked

(1),

(2),(3)and(4)iswrong?

classsample{

intn;

public:

sample(intval);//

(1)

~sample();//

(2)

private:

inta=2.5;//(3)

sample();//(4)

};

A.

(1)

(2)(3)(4)B.

(1)

(2)(3)C.

(2)D.(3)

9.Suppose :

classPoint

{

intx_,y_ ;

public :

Point() :

x_(0),y_(0){}

Point(intx,inty=0) :

x_(x),y_(y){}

} ;

voidmain(){

Pointa

(2),b[4],*c[4] ;

}

HowmanytimestheconstructorsofclassPointwillbecalled ?

A.5 B.4C.3D.2

10.Suppose :

classFoo{intbar;} ;

whichofthefollowingiscorrect ?

A.barisaprivatedatamemberofclassFoo

B.barisafrienddatamemberofclassFoo

C.barisaprotecteddatamemberofclassFoo

D.barisapublicdatamemberofclassFoo

考生注意:

考试时间120分钟试卷总分100分答案写在答题页共6页第1页

 

专业

班级

学号

姓名

11.Whichofthefollowingcodemarked

(1),

(2),(3)and(4)iscorrectfunctiondefinition?

classAA{

inta;

public:

intgetRef()const{return&a;}//

(1)

intgetValue()const{returna;}//

(2)

voidset(intn)const{a=n;}//(3)

friendvoidshow(AAaa)const{cout<

}

A.(4)B.(3)C.

(2)D.

(1)

12.Suppose:

classMyClass{

public:

intnumber;

voidset(inti){number=i;}

};

intnumber=3;

voidmain(){

MyClassmy;

intnumber=10;

my.set(5);

cout<

my.set(number);

cout<

my.set(:

:

number);

cout<

}

Whichofthefollowingiscorrectoutput?

A.3105B.3510

C.5103D.5310

13.Whichofthefollowingiscorrectoutput?

classAA{

intn;

public:

AA(intk):

n(k){}

intget(){returnn;}

intget()const{returnn+1;}

};

voidmain(){

AAa(4);

constAAb(5);

cout<

}

A.46B.66

C.44D.45

共6页第2页

 

专业

班级

学号

姓名

14.Suppose:

classMyBase{

private:

intk;

public:

voidset(intn){k=n;}

};

classMyDerived:

protectedMyBase{

protected:

intj;

public:

voidf(){j=10;}

voidg(){j=20;}

};

HowmanyprotecteddatamembersandfunctionmembersinclassMyDeriver?

A.1B.2C.3D.4

15.Suppose:

classBase{

public:

Base(){cout<<”BaseConstructor”<

~Base(){cout<<”BaseDestructor”<

};

classDerived:

publicBase{

public:

Derived(){cout<<”DerivedConstructor”<

~Derived(){cout<<”DerivedDestructor”<

};

voidmain(){Derivedobj;}

Whichofthefollowingiscorrectoutput?

A.BaseConstructorB.DerivedConstructor

DerivedConstructorBaseConstructor

BaseDestructorBaseDestructor

DerivedDestructorDerivedDestructor

C.BaseConstructorD.DerivedConstructor

DerivedConstructorBaseConstructor

DerivedDestructorDerivedDestructor

BaseDestructorBaseDestructor

16.Suppose:

classBase{

public:

virtualvoidfun(){cout<<1;}

};

classDerived:

publicBase{

public:

voidfun(){cout<<2;}

};

voidmain(){

Base*pB=newDerived;

pB->fun();

deletepB;

}

Whichofthefollowingiscorrectoutput?

A.1B.12C.2D.21

17.Whichoneofthefollowingoperatorsinc++cannotbeoverload?

A.?

:

B.[]C.&&D.new

18.Whichofthefollowingcodemarked

(1),

(2),(3)and(4)iswrong?

classA{

public:

voidfun(){}

};

classB{

public:

voidfun(){}//

(1)

voidgun(){fun();}//

(2)

};

classC:

publicA,publicB{

private:

intb;

public:

voidgun(){}//(3)

voidhun(){fun();}//(4)

};

A.(4)B.(3)C.

(2)D.

(1)

19.Whichofthefollowingwillbecalledbyfun(8,3.1)?

A.fun(double,double)

Btemplatefun(T1,T2)

Cfun(double,int)

Dfun(charfloat)

20.Suppose:

template

classTAdd{

Tx,y;

public:

TAdd(Ta,Tb):

x(a),y(b){}

intadd(){returnx+y;}

};

voidmain()

{

TAddA(3.9,4.9);

TAddB(4.5,6.8);

cout<

}

whichofthefollowingiscorrectoutput?

A.811

B.810

C.711

D.710

21.Suppose:

classTest{

public:

Test(){n+=2;}

~Test(){n-=3;}

staticintgetNum(){returnn;}

private:

staticintn;

};

intTest:

:

n=0;

voidmain()

{

Test*p=newTest;

deletep;

cout<<”n=”<

:

getNum()<

}

Whichofthefollowingiscorrectoutput?

A.n=2B.n=1C.n=0D.n=-1

22.Suppose:

classA{

public:

A(){cout<<"A";}

};

classB:

publicA{

public:

B(){cout<<"B";}

};

classC:

publicA{

Bb;

public:

C(){cout<<"C";}

};

voidmain(){

Cobj;

}

Whichofthefollowingiscorrectoutput?

A.ABACB.AABCC.ABCD.CAB

23.Suppose:

classONE{

public:

virtualvoidf(){cout<<"1";}

};

classTWO:

publicONE{

public:

TWO(){cout<<"2";}

};

共6页第3页

 

专业

班级

学号

姓名

classTHREE:

publicTWO{

public:

THREE(){cout<<"3";}

virtualvoidf(){TWO:

:

f();cout<<"3";}

};

voidmain()

{

ONEaa,*p;

TWObb;

THREEcc;

p=&cc;

p->f();

}

Whichofthefollowingiscorrectoutput?

A.22313B.21313C.2113D.2231

24.Suppose:

classLocation

{

public:

Location(intxx,intyy):

x(xx),y(yy){}

Location&operator+(Location&offset);

intgetX(){returnx;}

intgetY(){returny;}

private:

intx;

inty;

};

Location&Location:

:

operator+(Location&offset)

{

x=x+2*offset.x;

y=y+2*offset.y;

return*this;

}

voidmain()

{

Locationp1(10,20),off(8,8);

cout<<"("<

p1=p1+off;

cout<<"("<

}

Whichofthefollowingiscorrectoutput?

A.(10,20)(18,28)

B.(10,20)(26,36)

C.(10,20)(8,8)

D.(10,20)(16,16)

共6页第4页

25.Suppose:

template

classNum{

Tx;

public:

Num(){}

Num(Tx){this->x=x;}

Num&operator+(constNum&x2){

staticNumtemp;

temp.x=x+x2.x;

returntemp;

}

voiddisp(){cout<<"x="<

};

voidmain(){

NumA(2.8),B(3.8);

A=A+B;

A.disp();

}

Whichofthefollowingiscorrectoutput?

A.x=8B.x=7C.x=6D.x=5

得分

PartII、Pleasereadfollowingprogramsandgivetheresultswhicharemarkedwith【code1】to【code5】inprograms.(Totalquestions40points,each2points)

1.Supposetheprogram’soutputis:

Ctriangle:

a=3b=4c=5

Perimeter:

12

Area:

6

Pleasewritedownyouranswerinappointedposition.

#include

#include

usingnamespacestd;

classCtriangle{

public:

Ctriangle(doublex,doubley,doublez){

a=x;

b=y;

c=z;

}

doubleGetPerimeter(){//计算三角形周长

【code1】

}

doubleGetArea(){//计算三角形面积

doublep=GetPerimeter()/2;

returnsqrt(p*(p-a)*(p-b)*(p-c));

}

 

专业

班级

学号

姓名

voiddisplay(){

cout<<"Ctriangle:

"<<"a="<

【code2】//调用GetPerimeter()成员函数求当前对象的周长

【code3】//调用GetArea()成员函数求当前对象的面积

}

private:

doublea;

doubleb;

doublec;

};

voidmain()

{

【code4】//定义一个边长为3,4,5的Triangle类的对象T

【code5】//调用T的成员函数display()输出

}

2.Supposetheprogram’soutputis:

ABA-B-A-A

Pleasewritedownyouranswerinappointedposition.

#include

usingnamespacestd;

classA{

public:

A(){【code1】}//在命令行窗口输出字符串

~A(){【code2】}//在命令行窗口输出字符串

};

classB:

【code3】{//类B保护派生自类A

A*p;

public:

B(){

cout<<”B”;

【code4】//产生一个A类的动态对象,并将首地址赋给指针p

}

~B(){

cout<<”-B”;

【code5】//释放指针p所指向的内存空间

}

};

voidmain(){

Bobj;

}

3.Supposetheprogram’soutputis:

CreatingB

EndofB

EndofA

Pleasewritedownyouranswerinappointedposition.

#include

usingnamespacestd;

classA{

public:

A(){}

共6页第5页

【code1】{cout<<”EndofA”<

};

classB:

【code2】//类B公有派生自类A

{

public:

B(){【code3】}//在命令行窗口输出字符串

~B(){【code4】}//在命令行窗口输出字符串

};

voidmain()

{

【code5】//产生B类的动态对象,并将其首地址赋值给A类的指针pa

deletep;//释放指针pa所指向的内存空间

}

4.Supposetheprogram’soutputis:

Catiscrying!

Dogiscrying!

Pleasewritedownyouranswerinappointedposition.

#include

usingnamespacestd;

classAnimal{//定义抽象类Animal

public:

【code1】//定义纯虚函数cry()

};

classCat:

publicAnimal

{

public:

voidcry(){

【code2】//在命令行窗口输出字符串

}

}

classDog:

publicAnimal

{

public:

voidcry(){

【code3】//在命令行窗口输出字符串

}

}

voidmain(){

【code4】//声明一个指向抽象类Animal的指针pA

pA=newCat();

pA->cry()

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

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2