C++面向对象程序设计模拟试题2.docx
《C++面向对象程序设计模拟试题2.docx》由会员分享,可在线阅读,更多相关《C++面向对象程序设计模拟试题2.docx(11页珍藏版)》请在冰豆网上搜索。
![C++面向对象程序设计模拟试题2.docx](https://file1.bdocx.com/fileroot1/2022-11/16/ccce8e36-e437-44a8-83cf-13a5e4eb2f4c/ccce8e36-e437-44a8-83cf-13a5e4eb2f4c1.gif)
C++面向对象程序设计模拟试题2
C++面向对象程序设计模拟试题二
一、单项选择题(本大题共10小题,每小题2分,共20分)在每小题列出的四个备选项中,只有一个是符合题目要求的,请将其代码填写在题后的括号内。
错选、多选或未选均无分。
1.说明内联函数的关键字是()。
A)inlineB)virtualC)defineD)static
2.假定CAb为一个类,则执行CAboX;语句时将自动调用该类的()
A)有参构造函数B)无参构造函数
C)拷贝构造函数D)赋值重载函数
3.cin是某个类的标准对象的引用,该类是()。
A)ostreamB)istreamC)stdoutD)stdin
4.下面的哪个保留字不能作为函数的返回类型?
()
A)voidB)intC)templateD)long
5.派生类的成员函数不能访问基类的()。
A)保护成员B)公有成员
C)私有成员D)前面各选项都正确
6.在语句“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
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.SetX(16);
cout<u.SetY(18);
cout<cout<cout<return0;
}
上面程序的输出结果为:
2.阅读下面程序,写出输出结果。
#include
usingnamespacestd;
template
classTest
{
public:
Test(Typea[],intiSize):
elem(a){size=iSize;}
voidPrint()const{for(inti=0;iprivate:
Type*elem;
intsize;
};
intmain()
{
inta[]={1,0,8};
doubleb[]={1.6,1.8};
Testar1(a,3);
ar1.Print();
Testar2(b,sizeof(b)/sizeof(double));
ar2.Print();
cout<return0;
}
上面程序的输出结果为:
3.阅读下面程序,写出输出结果。
#include
usingnamespacestd;
classGoods
{
public:
Goods(intw):
weight(w){totalWeight=totalWeight+w;}
Goods(constGoods&g)
{
weight=g.weight;
totalWeight=totalWeight+weight;
}
~Goods(){totalWeight=totalWeight-weight;}
voidPrint()const;
staticintGetTotalWeight(){returntotalWeight;}
private:
intweight;
staticinttotalWeight;
};
intGoods:
:
totalWeight=0;
voidGoods:
:
Print()const
{
cout<weight<<""<totalWeight<<"";
}
intmain()
{
Goodsg1(6);
g1.Print();
Goodsg2(g1);
g2.Print();
cout<:
GetTotalWeight();
cout<return0;
}
上面程序的输出结果为:
4.阅读下面程序,写出输出结果。
#include
usingnamespacestd;
template
classTest
{
public:
Test(Typea=0,Typeb=0,Typec=0):
z(c){x=a;y=b;}
voidPrint()
{
cout<cout<}
voidPrint()const
{
cout<}
private:
Typex,y;
constTypez;
};
intmain()
{
Testt1;
t1.Print();
Testt2(1,9,6);
t2.Print();
constTestt3(0,6,1.8);
t3.Print();
return0;
}
上面程序的输出结果为:
5.阅读下面程序,写出输出结果。
#include
usingnamespacestd;
template
TypeMax(constType&a,constType&b)
{
if(a
elsereturna;
}
template
TypeMin(constType&a,constType&b)
{
if(a
elsereturnb;
}
intmain()
{
doublex=5.38,y=6.09;
cout<(x,y)<<"";
cout<(x,y)<return0;
}
上面程序的输出结果为:
6.阅读下面程序,写出输出结果。
#include
usingnamespacestd;
classA
{
public:
A(){cout<<"A"<~A(){cout<<"~A"<};
classB:
publicA
{
public:
B(){cout<<"B"<~B(){cout<<"~B"<};
intmain(void)
{
Bobj;
return0;
}
上面程序的输出结果为:
四、完成程序填题(本大题共4个小题,每小题3分,共12分)下面程序都留有空白,请将程序补充完整。
1.将如下程序补充完整。
#include
usingnamespacestd;
classA
{
private:
intn;
public:
A(intn){[1]=n;}//将数据成员n初始化为形参n
voidShow()const{cout<};
intmain()
{
Ai=8;
i.Show();
return0;
}
2.将如下程序补充完整。
#include
usingnamespacestd;
classA
{
private:
inta;
public:
A(intm):
a(m){}
voidShow()const{cout<};
classB:
A
{
public:
B(intm):
[2]{}//将数据成员a初始化为m
voidShow()const{A:
:
Show();}
};
intmain()
{
Bobj(8);
obj.Show();
return0;
}
3.将如下程序补充完整。
#include
usingnamespacestd;
classTest
{
private:
staticintnum;
public:
Test(){num++;}
~Test(){num--;}
staticvoidShowObjectNum(){cout<};