C++面向对象程序设计模拟题答案.docx
《C++面向对象程序设计模拟题答案.docx》由会员分享,可在线阅读,更多相关《C++面向对象程序设计模拟题答案.docx(38页珍藏版)》请在冰豆网上搜索。
C++面向对象程序设计模拟题答案
C++面向对象程序设计模拟试题一参考答案
一、单项选择题(本大题共10小题,每小题2分,共20分)在每小题列出的四个备选项中,只有一个是符合题目要求的,请将其代码填写在题后的括号内。
错选、多选或未选均无分。
1.B)2.A)3.A)4.C)5.C)
6.D)7.D)8.D)9.A)10.A)
二、填空题(本大题共5小题,每小题2分,共10分)不写解答过程,将正确的答案写在每小题的空格内。
错填或不填均无分。
1.参考答案:
new
2.参考答案:
class或typename
3.参考答案:
重载
4.参考答案:
对象
5.参考答案:
静态
三、程序分析题(本大题共6小题,每小题5分,共30分)给出下面各程序的输出结果。
1.参考答案:
97215
2.参考答案:
5686.89.6
3.参考答案:
61822
4.参考答案:
0
0
1
6
18
5.参考答案:
0
1
2
1
end
6.参考答案:
无参构造函数
含参构造函数a=1
复制构造函数
析构函数
析构函数
析构函数
四、完成程序填题(本大题共4个小题,每小题3分,共12分)下面程序都留有空白,请将程序补充完整。
1.参考答案:
[1]this->num或Integer:
:
num
2.参考答案:
[2]A(m),b(n)
3.参考答案:
[3]intPoint:
:
count=0;
4.参考答案:
[4]Complexoperator+
五、编程题(本大题共2小题,第1小题12分,第2小题16分,共28分)
1.参考程序:
#include
usingnamespacestd;
template
TypeAbs(Typea)
{
if(a>=0)returna;
elsereturn-a;
}
intmain()
{
cout<cout<cout<cout<return0;
}
2.参考程序:
#include
usingnamespacestd;
classComplex
{
public:
Complex(doubler,doublei=0)
{
real=r;
image=i;
}
voidShow()
{
cout<if(image>0)cout<<"+"<elseif(image<0)cout<<"-"<<-image<<"i"<elsecout<}
Complexoperator+(constComplex&obj)
{
Complextemp(real+obj.real,image+obj.image);
returntemp;
}
private:
doublereal,image;
};
intmain()
{
Complexz1(2,6),z2(3,8),z3(0);
z1.Show();
z2.Show();
z3.Show();
z3=z1+z2;
z3.Show();
return0;
}
C++面向对象程序设计模拟试题二参考答案
一、单项选择题(本大题共10小题,每小题2分,共20分)在每小题列出的四个备选项中,只有一个是符合题目要求的,请将其代码填写在题后的括号内。
错选、多选或未选均无分。
1.A)2.B)3.B)4.C)5.C)
6.C)7.A)8.C)9.B)10.B)
二、填空题(本大题共5小题,每小题2分,共10分)不写解答过程,将正确的答案写在每小题的空格内。
错填或不填均无分。
1.参考答案:
2
2.参考答案:
多态
3.参考答案:
共享
4.参考答案:
函数名
5.参考答案:
delete
三、程序分析题(本大题共6小题,每小题5分,共30分)给出下面各程序的输出结果。
1.参考答案:
0
16
18
6
8
2.参考答案:
1081.61.8
3.参考答案:
6661212
4.参考答案:
0
0
1
9
1.8
5.参考答案:
6.0965.385
6.参考答案:
A
B
~B
~A
四、完成程序填题(本大题共4个小题,每小题3分,共12分)下面程序都留有空白,请将程序补充完整。
1.参考答案:
[1]this->n或A:
:
n
2.参考答案:
[2]A(m)
3.参考答案:
[3]intTest:
:
num=0;
4.参考答案:
[4]operatorint()
五、编程题(本大题共2小题,第1小题12分,第2小题16分,共28分)
1.参考程序:
#include
usingnamespacestd;
template
TypeSum(Typea[],intn)
{
TypetSum=0;
for(inti=0;i{
tSum=tSum+a[i];
}
returntSum;
}
intmain()
{
inta[]={1,2,3};
doubleb[]={1.5,2.8,8.9,8};
cout<cout<return0;
}
2.参考程序:
#include
usingnamespacestd;
classShape
{
public:
virtualdoubleGetPerimeter()const=0;
};
classRectangle:
publicShape
{
public:
Rectangle(doublew,doubleh)
{
width=w;
height=h;
}
doubleGetPerimeter()const
{
return2*(width+height);
}
private:
doublewidth,height;
};
classCircle:
publicShape
{
public:
Circle(doubler)
{
radius=r;
}
doubleGetPerimeter()const
{
return3.1415926*radius*radius;
}
private:
doubleradius;
};
intmain()
{
RectangleoRectangle(2,3);
cout<CircleoCircle(10);
cout<return0;
}
C++面向对象程序设计模拟试题三参考答安全
一、单项选择题(本大题共10小题,每小题2分,共20分)在每小题列出的四个备选项中,只有一个是符合题目要求的,请将其代码填写在题后的括号内。
错选、多选或未选均无分。
1.C)2.D)3.A)4.B)5.D)
6.A)7.C)8.C)9.C)10.A)
二、填空题(本大题共5小题,每小题2分,共10分)不写解答过程,将正确的答案写在每小题的空格内。
错填或不填均无分。
1.参考答案:
virtualintfun()=0;
2.参考答案:
static
3.参考答案:
CTest
4.参考答案:
构造函数
5.参考答案:
private或私有
三、程序分析题(本大题共6小题,每小题5分,共30分)给出下面各程序的输出结果。
1.参考答案:
A()
A()
~A()
end
~A()
2.参考答案:
82345
3.参考答案:
A
B
A
B
4.参考答案:
15
1
2
1.1
2.2
5.参考答案:
1
8
6
13
6.参考答案:
2
8
0
end
四、完成程序填题(本大题共4个小题,每小题3分,共12分)下面程序都留有空白,请将程序补充完整。
1.参考答案:
[1]static
2.参考答案:
[2]a+i.a或this->a+i.a
3.参考答案:
[3]char*
4.参考答案:
[4]virtual
五、编程题(本大题共2小题,第1小题12分,第2小题16分,共28分)
1.参考程序:
#include
usingnamespacestd;
template
TAverage(Ta[],intn)
{
Ts=0;
for(inti=0;is=s+a[i];
returns/n;
}
intmain()
{
doublea[]={11.8,2,3,4,5.5,6.8,7,8,9};
cout<return0;
}
2.参考程序:
#include
usingnamespacestd;
classPerson
{
protected:
charname[18];
intage;
charsex[3];
public:
Person(charnm[],intag,charsx[])
{
strcpy(name,nm);
age=ag;
strcpy(sex,sx);
}
voidShow()const
{
cout<<"姓名:
"<cout<<"年龄:
"<cout<<"性别:
"<}
};
classTeacher:
virtualpublicPerson
{
protected:
chartitle[18];
public:
Teacher(charnm[],intag,charsx[],chartl[]):
Person(nm,ag,sx)
{strcpy(title,tl);}
voidShow()const
{
Person:
:
Show();
cout<<"职称:
"<
cout<}
};
classCadre:
virtualpublicPerson
{
protected:
charpost[18];
public:
Cadre(charnm[],intag,charsx[],charpt[]):
Person(nm,ag,sx)
{strcpy(post,pt);}
voidShow()const
{
Person:
:
Show();
cout<<"职务:
"<cout<}
};
classTeacherCadre:
publicTeacher,publicCadre
{
protected:
doublewages;
public:
TeacherCadre(charnm[],intag,charsx[],chartl[],charpt[],doublewg)
:
Person(nm,ag,sx),Teacher(nm,ag,sx,tl),Cadre(nm,ag,sx,pt)
{wages=wg;}
voidShow()const
{
Person:
:
Show();
cout<<"职称:
"<
cout<<"职务:
"<cout<<"工资:
"<cout<}
};
intmain()
{
TeacherobjTeacher("文冠杰",48,"男","教授");
CadreobjCadre("周杰",56,"男","院长");
TeacherCadreobjTeacherCadre("李靖",50,"女","教授","院长",6890);
objTeacher.Show();
objCadre.Show();
objTeacherCadre.Show();
return0;
}
C++面向对象程序设计模拟试题四参考答巡查
一、单项选择题(本大题共10小题,每小题2分,共20分)在每小题列出的四个备选项中,只有一个是符合题目要求的,请将其代码填写在题后的括号内。
错选、多选或未选均无分。
1.C)2.C)3.C)4.A)5.C)
6.A)7.B)8.D)9.A)10.A)
二、填空题(本大题共5小题,每小题2分,共10分)不写解答过程,将正确的答案写在每小题的空格内。
错填或不填均无分。
1.参考答案:
基类
2.参考答案:
template
3.参考答案:
operator[]
4.参考答案:
对象
5.参考答案:
析构函数
三、程序分析题(本大题共6小题,每小题5分,共30分)给出下面各程序的输出结果。
1.参考答案:
ClassA
ClassB
ClassA
ClassB
ClassB
2.参考答案:
16916
3.参考答案:
1
2
3
4
3
4.参考答案:
A()
B()
B:
:
f()
~B()
~A()
5.参考答案:
constructor,i=0,destructor
6.参考答案:
00
23
四、完成程序填题(本大题共4个小题,每小题3分,共12分)下面程序都留有空白,请将程序补充完整。
1.参考答案:
[1]a(x)
2.参考答案:
[2]operatorint
3.参考答案:
[3]realPart+a.realPart,imagePart+a.imagePart或this->realPart+a.realPart,this->imagePart+a.imagePart
4.参考答案:
intTest:
:
count=
五、编程题(本大题共2小题,第1小题12分,第2小题16分,共28分)
1.参考程序:
#include
usingnamespacestd;
template
TypeMin(Typea[],intn)
{
Typem=a[0];
for(inti=1;iif(a[i]returnm;
}
intmain()
{
inta[]={1,2,3,4,5,6,7,8,9};
cout<return0;
}
2.参考程序:
#include
usingnamespacestd;
constdoublePI=3.1415926;
classShape
{
public:
Shape(){}
virtual~Shape(){}
virtualvoidShowArea()const=0;
staticdoubletotalArea;
staticvoidShowTotalArea(){cout<<"总面积:
"<};
classCircle:
publicShape
{
private:
doubleradius;
public:
Circle(doubler):
radius(r){totalArea+=PI*r*r;}
~Circle(){}
virtualvoidShowArea()const{cout<<"圆面积:
"<};
classRectangle:
publicShape
{
private:
doublelength;
doublewidth;
public:
Rectangle(doublel,doublew):
length(l),width(w){totalArea+=l*w;}
~Rectangle(){}
virtualvoidShowArea()const{cout<<"矩形面积:
"<};
classSquare:
publicShape
{
private:
doublelength;
public:
Square(doublel):
length(l){totalArea+=l*l;}
~Square(){}
virtualvoidShowArea()const{cout<<"正方形面积:
"<};
doubleShape:
:
totalArea=0;
intmain()
{
Circlec
(1);
c.ShowArea();
Rectangler(1,2);
r.ShowArea();
Squarez(3);
z.ShowArea();
Shape:
:
ShowTotalArea();
return0;
}
C++面向对象程序设计模拟试题五参考答案
一、单项选择题(本大题共10小题,每小题2分,共20分)在每小题列出的四个备选项中,只有一个是苻合题目要求的。
请将其代码填写在题后的括号内。
错选,多选或未选均无分。
1.A)2.B)3.C)4.C)5.A)
6.D)7.C)8.B)9.A)10.C)
二、填空题(本大题共5小题,每小题2分,共10分)不写解题过程,将正确的答案写在每小题的空格内,错填或不填均无分
1.参考答案:
oprator-
2.参考答案:
继承
3.参考答案:
私有
4.参考答案:
重载
5.参考答案:
delete
三、程序分析题(本大题共6小题,每小题5分,共30分)给出下面各程序的输出结果。
1.参考答案:
DestructorB!
7
DestructorA!
6
DestructorB!
0
DestructorA!
5
2.参考答案:
x=5,y=12
3.参考答案:
7
4.参考答案:
1
2
5.参考答案:
d=88i=88
6.参考答案:
0
1
2
3
4
四、完成程序填题(本大题共4个小题,每小题3分,共12分)下面程序都留有空白,请将程序补充完整。
1.参考答案:
[1]this->n=n或Test:
:
n=n
2.参考答案:
[2]A(x)
3.参考答案:
[3]intTest:
:
num=0;
4.参考答案:
[4]operator+
五、编程题(本大题共2小题,第1小题12分,第2小题16分,共28分)
1.参考程序:
#include
usingnamespacestd;
classDateInfo
{
private:
intyear,month,day;
public:
DateInfo():
year(2010),month(6),day(8){}
DateInfo(inty,intm,intd):
year(y),month(m),day(d){}
voidSet(inty,intm,intd)
{
year=y;
month=m;
day=d;
}
voidShow(){cout<};
intmain()
{
DateInfod1,d2(1988,8,18);
d1.Show();
d2.Show();
d2.Set(1999,9,19);
d2.Show();
return0;
}
2.参考程序:
#include
usingnamespacestd;
classStaff
{
protected:
intnum;
charname[18];
doublerateOfAttend;
doublebasicSal;
doubleprize;
staticintcount;
public:
Staff(){}
voidInput()
{
num=++count;
cout<<"请输入编号为"<