C++面向对象程序设计模拟试题完成.docx

上传人:b****2 文档编号:2266370 上传时间:2022-10-28 格式:DOCX 页数:58 大小:41.02KB
下载 相关 举报
C++面向对象程序设计模拟试题完成.docx_第1页
第1页 / 共58页
C++面向对象程序设计模拟试题完成.docx_第2页
第2页 / 共58页
C++面向对象程序设计模拟试题完成.docx_第3页
第3页 / 共58页
C++面向对象程序设计模拟试题完成.docx_第4页
第4页 / 共58页
C++面向对象程序设计模拟试题完成.docx_第5页
第5页 / 共58页
点击查看更多>>
下载资源
资源描述

C++面向对象程序设计模拟试题完成.docx

《C++面向对象程序设计模拟试题完成.docx》由会员分享,可在线阅读,更多相关《C++面向对象程序设计模拟试题完成.docx(58页珍藏版)》请在冰豆网上搜索。

C++面向对象程序设计模拟试题完成.docx

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<m_iVar<<""<m_iCount<<"";

}

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);

cout<

}

voidfun(int*pa,intn)

{for(intI=0;I

*(pa+7)+=*(pa+I);

}

3、#include

voidff(intx),ff(doublex);

voidmain()

{floata(88.18);

ff(a);

charb('a');

ff(b);

}

voidff(intx)

{cout<<"ff(int):

"<

voidff(doublex)

{cout<<"ff(double):

"<

4、#include

classAA

{public:

AA(inti,intj)

{A=i;B=j;cout<<"Constructor\n";}

AA(AA&obj)

{A=obj.A+1;B=obj.B+2;cout<<"Copy_Constructor\n";}

~AA()

{cout<<"Destructor\n";}

voidprint()

{cout<<"A="<

private:

intA,B;

};

voidmain()

{AAa1(2,3);

AAa2(a1);

a2.print();

AA*pa=newAA(5,6);

pa->print();

deletepa;

}

三、编程题(每题10分,共10×2=20分)

1、编写程序求1至100间所有素数之和,其中求素数要求用函数实现;

 

2、编程打印如下图形:

1

22

333

4444

55555

C++面向对象程序设计模拟试题三

一、单项选择题(本大题共10小题,每小题2分,共20分)

1.下面有关重载函数的描述中,正确的是()。

A)重载函数必须具有不同的返回值类型B)重载函数形参个数必须不同

C)重载函数必须具有不同的形参表D)重载函数名可以不同

2.假定MyCIass为一个类,那么下列的函数说明中,()为该类的析构函数。

A)void~MyClass();B)~MyClass(intn);C)MyClass();D)~MyClass();

3.()是以一种完全通用的方法来设计函数或类而不必预先说明将被使用的每个对象的类型。

A)模板B)类C)对象D)函数

4.下面关于静态成员函数的途术中错语的是()。

A.静态成员函数可以有返回值B.this指针可以指向静态成员函数

C.静态成员函数可以具有指针参数D.静态成员函数可有具有返回值类型

5.定义类模板时要使用关键字()。

A.privateB.publicC.deleteD.template

6.下列是重载乘法运算符的函数原型声明,其中错误的是()。

A)MyClassoperator*(double,double);B)MyClassoperator*(double,MyClass);

C)MyClassoperator*(MyClass,double);D)MyClassoperator*(MyClass,MyClass);

7.以下()成员函数表示纯虚函数。

A)virtualintfun(int)B)voidfun(int)=0C)virtualvoidfun()=0D)virtualvoidfun(int){}

8.关于纯虚函数,下列表述中正确的是()。

A)纯虚函数的声明总是以"=0"结束B)含有纯虚函数的类可以定义对象

C)含有纯虚函数的类是抽象类D)上面都是错误的

9.()解决二义性问题。

A.只

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 人文社科 > 法律资料

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1