1、C+面向对象程序设计模拟试题完成C+面向对象程序设计模拟试题一一、单项选择题(本大题共10小题,每小题2分,共20分1说明虚函数的关键字是( )。A. inline B. virtual C. define D. static2在每个C+程序中都必须包含有这样一个函数,该函数的函数名为( )。A. main B. MAIN C. name D. function3cout是某个类的标准对象的引用,该类是( )。 A. ostream B. istream C. stdout D. stdin4如果在类外有函数调用CPoint:func();则函数func()是类CPoint的( )。 A. 私
2、有静态成员函数 B. 公有非静态成员函数 C. 公有静态成员函数 B. 友元函数5. 如果class类中的所有成员在定义时都没有使用关键字public、private或protected,则所有成员缺省定义为( )。A. public B. protected C. private Dstatic 6一个类的所有对象共享的是( )。A. 私有数据成员 B. 公有数据成员 C. 保护数据成员 D. 静态数据成员7动态联编所支持的多态性称为( )。A. 虚函数 B. 继承 C. 编译时多态性 D. 运行时多态性8定义类模板时要使用关键字( )。A. const B. new C. delete D
3、. template9对虚基类的定义( )。A. 不需要使用虚函数 B. 必须使用虚函数C. 必须使用privatD. 必须使用public10类型转换函数( )。 A. 不能带有参数 B. 只能带一个参数 C. 只能带2个参数D. 只能带3个参数四、程序分析题(本大题共4小题,每小题5分,共20分)给出下面各程序的输出结果。1阅读下面程序,写出输出结果。#include using namespace std;class CArraypublic: CArray(int iArray, int iSize):m_pArray(iArray), m_iSize(iSize) int GetSi
4、ze() return m_iSize; int &operator(int iIndex) return m_pArrayiIndex - 1; private: int *m_pArray; / 指向一个数组空间 int m_iSize; / 数组元素个数;int main() int s=3, 7, 2, 1, 5; CArray oArray(s, 5); oArray1 = 9; for (int i = 1; i = 5; i+) cout oArrayi ; cout endl; return 0;上面程序的输出结果为:2阅读下面程序,写出输出结果。#include using
5、namespace std;template void Print(Type a, int n) for (int i = 0; i n; i+) cout ai ; int main() int a = 5, 6, 8; double b = 6.8, 9.6; Print(a, sizeof(a) / sizeof(int); Print(b, 2); cout endl; return 0;上面程序的输出结果为:3阅读下面程序,写出输出结果。#include using namespace std;class CTestpublic: CTest(int iVar):m_iVar(iVa
6、r) m_iCount+; CTest() void Print() const; static int GetCount() return m_iCount; private: int m_iVar; static int m_iCount;int CTest:m_iCount = 0;void CTest:Print() const cout m_iVar m_iCount ;int main() CTest oTest1(6); oTest1.Print(); CTest oTest2(8); oTest2.Print(); cout CTest:GetCount(); cout end
7、l; return 0;上面程序的输出结果为:4阅读下面程序,写出输出结果。#include using namespace std;class CTestpublic: CTest(int iX = 0, int iY = 0, int iZ = 0):m_iZ(iZ) m_iX = iX; m_iY = iY; void Print() cout m_iX endl; cout m_iY endl; void Print() const cout m_iZ endl; private: int m_iX, m_iY; const int m_iZ;int main() CTest oTes
8、t1; oTest1.Print(); CTest oTest2(1, 6, 8); oTest2.Print(); const CTest oTest3(6, 0, 18); oTest3.Print(); cout endl; return 0;上面程序的输出结果为:六、编程题(本大题共2个小题,每小题8分,共16分)1编写一个函数模板,用于求参数的绝对值,并编写测试程序进行测试。函数模板声明如下:template Type Abs(Type tVar)2定义一个复数类CComplex,定义带有2个参数(其中一个为缺省参数)的构造函数,显示复数值的函数Show(), 重载“+”运算符(用成
9、员函数实现),并编写测试程序进行测试。C+面向对象程序设计模拟试题二二、读程题,写出程序的运行结果。(12题每题6分,34题每题8分,共28分)1、#includevoid main()int i(0);while(+i)if(i= =10) break;if(i%3!=1) continue;coutiendl;2、#include int a8=1,2,3,4,5,6,7;void fun(int *pa,int n);void main( ) int m=8; fun(a,m); couta7endl; void fun(int *pa,int n) for (int I=0;In-1;
10、I+) *(pa+7)+= *(pa+I);3、#includevoid ff(int x),ff(double x);void main() float a(88.18);ff(a);char b(a);ff(b); void ff(int x) coutff(int): xendl; void ff(double x) coutff(double): xendl;4、#include class AA public: AA(int i,int j) A=i;B=j;coutConstructorn; AA(AA &obj) A=obj.A+1;B=obj.B+2;coutCopy_Cons
11、tructorn; AA() coutDestructorn; void print() coutA=A,B=Bprint(); delete pa; 三、编程题(每题10分,共102=20分)1、编写程序求1至100间所有素数之和,其中求素数要求用函数实现;2、编程打印如下图形:122333444455555C+面向对象程序设计模拟试题三一、单项选择题(本大题共10小题,每小题2分,共20分)1下面有关重载函数的描述中,正确的是( )。A)重载函数必须具有不同的返回值类型 B)重载函数形参个数必须不同C)重载函数必须具有不同的形参表 D)重载函数名可以不同2假定MyCIass为一个类,那么下
12、列的函数说明中,( )为该类的析构函数。A)voidMyClass(); B)MyClass(int n); C)MyClass( ); D)MyClass( );3( )是以一种完全通用的方法来设计函数或类而不必预先说明将被使用的每个对象的类型。 A)模板 B)类 C)对象 D)函数4下面关于静态成员函数的途术中错语的是( )。A. 静态成员函数可以有返回值 B. this指针可以指向静态成员函数C. 静态成员函数可以具有指针参数 D. 静态成员函数可有具有返回值类型5定义类模板时要使用关键字( )。A. private B. public C. delete D. template6下列是
13、重载乘法运算符的函数原型声明,其中错误的是( )。A)MyClass operator*(double,double); B)MyClass operator*(double,MyClass);C)MyClass operator*(MyClass,double); D)MyClass operator*(MyClass,MyClass);7以下( )成员函数表示纯虚函数。A)virtual int fun(int) B)void fun(int)=0 C)virtual void fun()=0 D)virtual void fun(int)8关于纯虚函数,下列表述中正确的是( )。A)纯虚函数的声明总是以=0结束 B)含有纯虚函数的类可以定义对象C)含有纯虚函数的类是抽象类 D)上面都是错误的 9( )解决二义性问题。A. 只
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1