川大c++期末复习题Word文件下载.docx
- 文档编号:19839530
- 上传时间:2023-01-10
- 格式:DOCX
- 页数:14
- 大小:18.99KB
川大c++期末复习题Word文件下载.docx
《川大c++期末复习题Word文件下载.docx》由会员分享,可在线阅读,更多相关《川大c++期末复习题Word文件下载.docx(14页珍藏版)》请在冰豆网上搜索。
A)1种B)2种C)3种D)4种
10.基类和派生类可以分别称为()。
A)“大类”和“小类”B)“父类”和“子类”
C)“小类”和“大类”D)“子类”和“父类”
二、填空题(本大题共5小题,每小题2分,共10分)不写解答过程,将正确的答案写在每小题的空格内。
错填或不填均无分。
1.设函数max是由函数模板实现的,并且max(3.5,5)和max(3,5)都是正确的函数调用,则此函数模板具有()个类型参数。
2.在C++中,函数重载与虚函数帮助实现了类的()性。
3.由static修饰的数据成员为该类的所有对象()。
4.重载函数一般在参数类型或参数个数上不同,但()相同。
5.使用new建立的动态对象在不用时应该用()释放所占用的空间。
三、程序分析题(本大题共6小题,每小题5分,共30分)给出下面各程序的输出结果。
1.阅读下面程序,写出输出结果。
#include<
iostream>
usingnamespacestd;
classPoint
{
public:
Point(inta=0,intb=0):
x(a),y(b){}
intGetX()const{returnx;
}
intGetY()const{returny;
voidSetX(inta){x=a;
voidSetY(inta){y=a;
private:
intx;
inty;
};
intmain()
Pointu;
constPointv(6,8);
cout<
u.GetX()<
endl;
u.SetX(16);
u.SetY(18);
u.GetY()<
v.GetX()<
v.GetY()<
return0;
}
上面程序的输出结果为:
2.阅读下面程序,写出输出结果。
template<
classType>
classTest
Test(Typea[],intiSize):
elem(a){size=iSize;
voidPrint()const{for(inti=0;
i<
size;
i++)cout<
elem[i]<
"
;
Type*elem;
intsize;
inta[]={1,0,8};
doubleb[]={1.6,1.8};
Test<
int>
ar1(a,3);
ar1.Print();
double>
ar2(b,sizeof(b)/sizeof(double));
ar2.Print();
3.阅读下面程序,写出输出结果。
classGoods
Goods(intw):
weight(w){totalWeight=totalWeight+w;
Goods(constGoods&
g)
{
weight=g.weight;
totalWeight=totalWeight+weight;
~Goods(){totalWeight=totalWeight-weight;
voidPrint()const;
staticintGetTotalWeight(){returntotalWeight;
intweight;
staticinttotalWeight;
intGoods:
:
totalWeight=0;
voidGoods:
Print()const
this->
weight<
<
totalWeight<
Goodsg1(6);
g1.Print();
Goodsg2(g1);
g2.Print();
Goods:
GetTotalWeight();
4.阅读下面程序,写出输出结果。
Test(Typea=0,Typeb=0,Typec=0):
z(c){x=a;
y=b;
voidPrint()
cout<
x<
y<
voidPrint()const
z<
Typex,y;
constTypez;
float>
t1;
t1.Print();
t2(1,9,6);
t2.Print();
constTest<
t3(0,6,1.8);
t3.Print();
5.阅读下面程序,写出输出结果。
TypeMax(constType&
a,constType&
b)
if(a<
b)returnb;
elsereturna;
TypeMin(constType&
b)returna;
elsereturnb;
intmain()
doublex=5.38,y=6.09;
Max(x,y)<
Max<
(x,y)<
Min(x,y)<
Min<
6.阅读下面程序,写出输出结果。
classA
A(){cout<
A"
}
~A(){cout<
~A"
classB:
publicA
B(){cout<
B"
~B(){cout<
~B"
intmain(void)
Bobj;
四、完成程序填题(本大题共4个小题,每小题3分,共12分)下面程序都留有空白,请将程序补充完整。
1.将如下程序补充完整。
intn;
A(intn){[1]=n;
}//将数据成员n初始化为形参n
voidShow()const{cout<
n<
intmain()
Ai=8;
i.Show();
2.将如下程序补充完整。
inta;
A(intm):
a(m){}
a<
A
B(intm):
[2]{}//将数据成员a初始化为m
voidShow()const{A:
Show();
intmain()
Bobj(8);
obj.Show();
3.将如下程序补充完整。
staticintnum;
Test(){num++;
}
~Test(){num--;
staticvoidShowObjectNum(){cout<
num<
[3]//静态数据成员的初始化为0
intmain(void)
Test:
ShowObjectNum();
Testobj;
4.将如下程序补充完整。
classInteger
inti;
Integer(intx=0):
i(x){}
[4]{returni;
}//类类型转换函数,将类Integer转换为基本类型int
intmain()
{
Integera,b(18);
int(b)<
五、编程题(本大题共2小题,第1小题12分,第2小题16分,共28分)
1.编写一个函数模板,用于求数组中各元素之和,并编写测试程序进行测试。
函数模板声明如下:
TypeSum(Typea[],intn);
2.定义一个抽象类Shape,它有一个纯虚函数GetPerimeter();
派生出四边型类Rectangle和圆类Circle,在派生类中重载函数GetPerimeter(),用于求图形的周长,编写测试程序进行测试。
C++面向对象程序设计模拟试题二参考答案
1.A)2.B)3.B)4.C)5.C)
6.C)7.A)8.C)9.B)10.B)
1.参考答案:
2
2.参考答案:
多态
3.参考答案:
共享
4.参考答案:
函数名
5.参考答案:
delete
16
18
6
8
1081.61.8
6661212
1
9
1.8
6.0965.385
6.参考答案:
A
B
~B
~A
[1]this->
n或A:
n
[2]A(m)
[3]intTest:
num=0;
[4]operatorint()
1.参考程序:
TypeSum(Typea[],intn)
TypetSum=0;
for(inti=0;
n;
i++)
tSum=tSum+a[i];
returntSum;
inta[]={1,2,3};
doubleb[]={1.5,2.8,8.9,8};
Sum(a,3)<
Sum(b,4)<
2.参考程序:
classShape
virtualdoubleGetPerimeter()const=0;
classRectangle:
publicShape
Rectangle(doublew,doubleh)
width=w;
height=h;
doubleGetPerimeter()const
return2*(width+height);
doublewidth,height;
classCircle:
Circle(doubler)
radius=r;
return3.1415926*radius*radius;
doubleradius;
RectangleoRectangle(2,3);
oRectangle.GetPerimeter()<
CircleoCircle(10);
oCircle.GetPerimeter()<
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- c+ 期末 复习题
![提示](https://static.bdocx.com/images/bang_tan.gif)