C++面向对象程序设计模拟试题完成.docx
- 文档编号:2266370
- 上传时间:2022-10-28
- 格式:DOCX
- 页数:58
- 大小:41.02KB
C++面向对象程序设计模拟试题完成.docx
《C++面向对象程序设计模拟试题完成.docx》由会员分享,可在线阅读,更多相关《C++面向对象程序设计模拟试题完成.docx(58页珍藏版)》请在冰豆网上搜索。
C++面向对象程序设计模拟试题完成
C++面向对象程序设计模拟试题一
一、单项选择题(本大题共10小题,每小题2分,共20分
1.说明虚函数的关键字是()。
A.inlineB.virtualC.defineD.static
2.在每个C++程序中都必须包含有这样一个函数,该函数的函数名为()。
A.mainB.MAINC.nameD.function
3.cout是某个类的标准对象的引用,该类是()。
A.ostreamB.istreamC.stdoutD.stdin
4.如果在类外有函数调用CPoint:
:
func();则函数func()是类CPoint的()。
A.私有静态成员函数B.公有非静态成员函数C.公有静态成员函数B.友元函数
5.如果class类中的所有成员在定义时都没有使用关键字public、private或protected,则所有成员缺省定义为()。
A.publicB.protectedC.privateD.static
6.一个类的所有对象共享的是()。
A.私有数据成员B.公有数据成员C.保护数据成员D.静态数据成员
7.动态联编所支持的多态性称为()。
A.虚函数B.继承C.编译时多态性D.运行时多态性
8.定义类模板时要使用关键字()。
A.constB.newC.deleteD.template
9.对虚基类的定义()。
A.不需要使用虚函数B.必须使用虚函数C.必须使用privatD.必须使用public
10.类型转换函数()。
A.不能带有参数B.只能带一个参数C.只能带2个参数D.只能带3个参数
四、程序分析题(本大题共4小题,每小题5分,共20分)给出下面各程序的输出结果。
1.阅读下面程序,写出输出结果。
#include
usingnamespacestd;
classCArray
{
public:
CArray(intiArray[],intiSize):
m_pArray(iArray),m_iSize(iSize)
{}
intGetSize()
{returnm_iSize;
}
int&operator[](intiIndex)
{returnm_pArray[iIndex-1];
}
private:
int*m_pArray;//指向一个数组空间
intm_iSize;//数组元素个数
};
intmain()
{ints[]={3,7,2,1,5};
CArrayoArray(s,5);
oArray[1]=9;
for(inti=1;i<=5;i++)
{cout< }cout< return0; } 上面程序的输出结果为: 2.阅读下面程序,写出输出结果。 #include usingnamespacestd; template voidPrint(Typea[],intn) {for(inti=0;i {cout< } } intmain() {inta[]={5,6,8}; doubleb[]={6.8,9.6}; Print(a,sizeof(a)/sizeof(int)); Print(b,2); cout< return0; } 上面程序的输出结果为: 3.阅读下面程序,写出输出结果。 #include usingnamespacestd; classCTest {public: CTest(intiVar): m_iVar(iVar) {m_iCount++; } ~CTest() {} voidPrint()const; staticintGetCount() {returnm_iCount; } private: intm_iVar; staticintm_iCount; }; intCTest: : m_iCount=0; voidCTest: : Print()const {cout< } intmain() {CTestoTest1(6); oTest1.Print(); CTestoTest2(8); oTest2.Print(); cout< : GetCount(); cout< return0; } 上面程序的输出结果为: 4.阅读下面程序,写出输出结果。 #include usingnamespacestd; classCTest {public: CTest(intiX=0,intiY=0,intiZ=0): m_iZ(iZ) {m_iX=iX; m_iY=iY; } voidPrint() {cout< cout< } voidPrint()const {cout< } private: intm_iX,m_iY; constintm_iZ; }; intmain() {CTestoTest1; oTest1.Print(); CTestoTest2(1,6,8); oTest2.Print(); constCTestoTest3(6,0,18); oTest3.Print(); cout< return0; }上面程序的输出结果为: 六、编程题(本大题共2个小题,每小题8分,共16分) 1.编写一个函数模板,用于求参数的绝对值,并编写测试程序进行测试。 函数模板声明如下: template TypeAbs(TypetVar) 2.定义一个复数类CComplex,定义带有2个参数(其中一个为缺省参数)的构造函数,显示复数值的函数Show(),重载“+”运算符(用成员函数实现),并编写测试程序进行测试。 C++面向对象程序设计模拟试题二 二、读程题,写出程序的运行结果。 (1~2题每题6分,3~4题每题8分,共28分) 1、#include voidmain() { inti(0); while(++i) { if(i==10)break; if(i%3! =1)continue; cout< } } 2、#include inta[8]={1,2,3,4,5,6,7}; voidfun(int*pa,intn); voidmain() {intm=8; fun(a,m);
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C+ 面向 对象 程序设计 模拟 试题 完成