1、 一、单项选择题(本大题共10小题) 1. 关于面向对象的程序设计必需具备的关键要素,以下说法最正确的是( ) A. 抽象和封装 B. 抽象和多态性 C. 抽象、封装和继承性 D. 抽象、封装、继承和多态性 2.在下列成对的表达式中,运算符“+”的意义不相同的一对是( ) A. 5.0+2.0和5.0+2 B. 5.0+2.0和5+2.0 C. 5.0+2.0和5+2 D. 5+2.0和5.0+2 二、填空题(本大题共10小题) 3.在
2、已经定义了整型指针ip后,为了得到一个包括10个整数的动态数组并由ip指向这个数组,应使用语句_______________。ip=new int[10];矚慫润厲钐瘗睞枥庑赖。
4.在函数头与函数体之间加_____________关键字可以防止覆盖函数改变数据成员的值。
三、改错题(本大题共5小题)
5. 用横线标出下面main函数中的错误,说明错误原因并改正。
#include
3、t << "Member of Base0" << endl; } }; class Base1: public Base0 { //定义派生类Base1 public: //新增外部接口 int var1; }; class Base2: public Base0 { //定义派生类Base2 public: //新增外部接口 int var2; }; class Derived: public Base1, public Base2 { //定义派生类Derived聞創沟燴鐺險爱氇谴净。 public: //新增外部接口 int var; vo
4、id fun() { cout << "Member of Derived" << endl; }残骛楼諍锩瀨濟溆塹籟。
};
int main() { //程序主函数
Derived d; //定义Derived类对象d
d.var0=1;
d.fun0();
return 0;
}
6.下面的程序类B的定义中有一处错误,请用下横线标出错误并说明错误原因。
# include
5、py(name,nm);}
private:
char name[80];
};
class B:public A
{ public:
B(const char *nm):A(nm){ }
void PrintName( )const;
};
void B::PrintName( )const
{
cout<<“name:”< 6、s Point { //Point 类的定义
public: //外部接口
Point(int xx = 0, int yy = 0) { //构造函数
x = xx;
_______________;
}
Point(Point &p); //拷贝构造函数
private: //私有数据
int x, y;
};
//成员函数的实现
Point::Point(Point &p) {
x = p.x;
_______________
cout << "Calling the copy constructor" << endl;
}
7、8.根据注释在空白处填写适当内容。
class Location{
private:
int X,Y;
public:
void init(int initX,int initY);
int GetX( );
int GetY( );
};
void Location::init(int initX,int initY)
{ X=initX;
Y=initY;
}
8、 int Location::GetX( )
{ reutrn X; }
int Location::GetY( )
{ reutrn Y; }
# include 9、序分析题(本大题共5小题)
9.写出下面程序的输出结果:
# include 10、 int& operator[ ](int index){return pa[index-1];}
};
void main( )
{
int s[ ]={3,7,2,1,5,4};
FunArray ma(s,sizeof(s)/sizeof(int));
ma[3]=9;
for(int i=1;i<=ma.Size( );i++) cout< 11、>
using namespace std;
template






