C++面向对象程序设计模拟试题2Word文档下载推荐.docx
《C++面向对象程序设计模拟试题2Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《C++面向对象程序设计模拟试题2Word文档下载推荐.docx(11页珍藏版)》请在冰豆网上搜索。
![C++面向对象程序设计模拟试题2Word文档下载推荐.docx](https://file1.bdocx.com/fileroot1/2022-11/16/ccce8e36-e437-44a8-83cf-13a5e4eb2f4c/ccce8e36-e437-44a8-83cf-13a5e4eb2f4c1.gif)
”中,cout是()。
A)C++的关键字B)类名
C)对象名D)函数名
7.编译时多态性使用什么获得?
A)重载函数B)继承C)虚函数D)B和C
8.拷贝构造函数的参数通常是()。
A)无特殊要求B.指向对象的指针
C)本类对象的常引用D)对象
9.C++有几种联编?
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<