第四套模拟试题Word下载.docx
- 文档编号:6235787
- 上传时间:2023-05-06
- 格式:DOCX
- 页数:22
- 大小:26.61KB
第四套模拟试题Word下载.docx
《第四套模拟试题Word下载.docx》由会员分享,可在线阅读,更多相关《第四套模拟试题Word下载.docx(22页珍藏版)》请在冰点文库上搜索。
intk;
inta[3][3]={1,2,3,4,5,6,7,8,9};
for(k=0;
k<
3;
k++)cout<
a[k][2-k]<
”\t”;
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)--;
m<
”\t”<
n;
A.23B.32C.33D.22
题号
一
二
三
四
五
六
七
八
九
总分
得分
7.Suppose:
inti=100;
intfun(){
staticinti=10;
return++i;
}
fun();
fun()<
”,”<
i;
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){}
}
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;
intgetRef()const{return&
a;
}//
(1)
intgetValue()const{returna;
}//
(2)
voidset(intn)const{a=n;
}//(3)
friendvoidshow(AAaa)const{cout<
}//(4)
A.(4)B.(3)C.
(2)D.
(1)
12.Suppose:
classMyClass{
intnumber;
voidset(inti){number=i;
intnumber=3;
MyClassmy;
intnumber=10;
my.set(5);
my.number<
my.set(number);
my.set(:
number);
A.3105B.3510
C.5103D.5310
13.Whichofthefollowingiscorrectoutput?
AA(intk):
n(k){}
intget(){returnn;
intget()const{returnn+1;
AAa(4);
constAAb(5);
a.get()<
b.get();
A.46B.66
C.44D.45
共6页第2页
14.Suppose:
classMyBase{
intk;
voidset(intn){k=n;
classMyDerived:
protectedMyBase{
protected:
intj;
voidf(){j=10;
voidg(){j=20;
HowmanyprotecteddatamembersandfunctionmembersinclassMyDeriver?
A.1B.2C.3D.4
15.Suppose:
classBase{
Base(){cout<
”BaseConstructor”<
~Base(){cout<
”BaseDestructor”<
classDerived:
publicBase{
Derived(){cout<
”DerivedConstructor”<
~Derived(){cout<
”DerivedDestructor”<
voidmain(){Derivedobj;
A.BaseConstructorB.DerivedConstructor
DerivedConstructorBaseConstructor
BaseDestructorBaseDestructor
DerivedDestructorDerivedDestructor
C.BaseConstructorD.DerivedConstructor
16.Suppose:
virtualvoidfun(){cout<
1;
classDerived:
voidfun(){cout<
2;
Base*pB=newDerived;
pB->
fun();
deletepB;
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{
voidfun(){}//
(1)
voidgun(){fun();
}//
(2)
classC:
publicA,publicB{
intb;
voidgun(){}//(3)
voidhun(){fun();
}//(4)
A.(4)B.(3)C.
(2)D.
(1)
19.Whichofthefollowingwillbecalledbyfun(8,3.1)?
A.fun(double,double)
Btemplate<
classT1,classT2>
fun(T1,T2)
Cfun(double,int)
Dfun(charfloat)
20.Suppose:
template<
classT>
classTAdd{
Tx,y;
TAdd(Ta,Tb):
x(a),y(b){}
intadd(){returnx+y;
voidmain()
TAdd<
double>
A(3.9,4.9);
char>
B(4.5,6.8);
A.add()<
B.add();
whichofthefollowingiscorrectoutput?
A.811
B.810
C.711
D.710
21.Suppose:
classTest{
Test(){n+=2;
~Test(){n-=3;
staticintgetNum(){returnn;
staticintn;
intTest:
n=0;
Test*p=newTest;
deletep;
”n=”<
Test:
getNum()<
A.n=2B.n=1C.n=0D.n=-1
22.Suppose:
A(){cout<
"
A"
};
classB:
publicA{
B(){cout<
B"
classC:
Bb;
C(){cout<
C"
Cobj;
A.ABACB.AABCC.ABCD.CAB
23.Suppose:
classONE{
virtualvoidf(){cout<
1"
classTWO:
publicONE{
TWO(){cout<
2"
共6页第3页
classTHREE:
publicTWO{
public:
THREE(){cout<
3"
virtualvoidf(){TWO:
f();
voidmain()
{
ONEaa,*p;
TWObb;
THREEcc;
p=&
cc;
p->
A.22313B.21313C.2113D.2231
24.Suppose:
classLocation
Location(intxx,intyy):
x(xx),y(yy){}
Location&
operator+(Location&
offset);
intgetX(){returnx;
intgetY(){returny;
intx;
inty;
Location&
Location:
operator+(Location&
offset)
x=x+2*offset.x;
y=y+2*offset.y;
return*this;
Locationp1(10,20),off(8,8);
("
p1.getX()<
"
p1.getY()<
)"
\t"
p1=p1+off;
A.(10,20)(18,28)
B.(10,20)(26,36)
C.(10,20)(8,8)
D.(10,20)(16,16)
共6页第4页
25.Suppose:
classNum{
Tx;
Num(){}
Num(Tx){this->
x=x;
Num<
T>
&
operator+(constNum<
x2){
staticNum<
temp;
temp.x=x+x2.x;
returntemp;
voiddisp(){cout<
x="
x;
int>
A(2.8),B(3.8);
A=A+B;
A.disp();
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<
iostream>
cmath>
usingnamespacestd;
classCtriangle{
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(){
a="
a<
b="
b<
c="
c<
【code2】//调用GetPerimeter()成员函数求当前对象的周长
【code3】//调用GetArea()成员函数求当前对象的面积
private:
doublea;
doubleb;
doublec;
【code4】//定义一个边长为3,4,5的Triangle类的对象T
【code5】//调用T的成员函数display()输出
2.Supposetheprogram’soutputis:
ABA-B-A-A
Pleasewritedownyouranswerinappointedposition.
A(){【code1】}//在命令行窗口输出字符串
~A(){【code2】}//在命令行窗口输出字符串
classB:
【code3】{//类B保护派生自类A
A*p;
B(){
”B”;
【code4】//产生一个A类的动态对象,并将首地址赋给指针p
~B(){
”-B”;
【code5】//释放指针p所指向的内存空间
Bobj;
3.Supposetheprogram’soutputis:
CreatingB
EndofB
EndofA
A(){}
共6页第5页
【code1】{cout<
”EndofA”<
}//A类的析构函数
classB:
【code2】//类B公有派生自类A
B(){【code3】}//在命令行窗口输出字符串
~B(){【code4】}//在命令行窗口输出字符串
【code5】//产生B类的动态对象,并将其首地址赋值给A类的指针pa
//释放指针pa所指向的内存空间
4.Supposetheprogram’soutputis:
Catiscrying!
Dogiscrying!
classAnimal{//定义抽象类Animal
【code1】//定义纯虚函数cry()
classCat:
publicAnimal
voidcry(){
【code2】//在命令行窗口输出字符串
classDog:
【code3】//在命令行窗口输出字符串
【code4】//声明一个指向抽象类Animal的指针pA
pA=newCat();
pA->
cry()
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 第四 模拟 试题
![提示](https://static.bingdoc.com/images/bang_tan.gif)