第1题:
使用VC6打开考生文件夹下的工程test12_3,此工程包含一个test12_3.cpp,其中定义了类Base和类A,类A公有继承 Base,但这两个类的定义都并不完整。请按要求完成下列操作,将程序补充完整。
(1)定义枚举类型变量en,它包含两个枚举符front和back,请在注释“//**1**”之后添加适当的语句。
(2)在类Base中添加常成员虚函数void E()的定义,该函数输出“In Base E!”,请在注释“//**2**”之后添加适当的语句。
(3)在类A中添加常成员虚函数void E()的定义,该函数先调用基类中的虚函数 E()再输出“In AE!”,请在注释“//** 3**”之后添加适当的语句。
(4)完成类A构造函数的定义,请使用参数列表的形式初始化类A的成员,并输出“A constructor.”,请在注释“//** 4**”之后添加适当的语句。
输出结果如下:
Base constructor.
A constructor.
In BaseE!
In AE!
In BaseP!
In A!
1
A destructor.
Base destructor.
注意:除在指定的位置添加语句外,请不要改动程序中的其他语句。
源程序文件test12_3.cpp清单如下:
include<iostream .h>
// ** 1 **
class Base
{
protected:
int b1;
int b2;
public:
Base();
~Base();
int Getb1()const { return b1; }
void Setb1(int x){ b1 = x; }
int Getb2()const { return b2; }
void Setb2(int y) { b2 = y; }
void Print()const {cout<<"In Base P!"<<end1;}
// ** 2 **
};
Base::Base():b1(1),b2(5)
{
cout<<"Base constructor."<<endl;
}
Base::~Base()
{
cout<<"Base destructor."<<endl;
}
class A:public Base
{
protected:
en enA;
public:
A();
~A();
en GetColor()const { return enA; }
void SetColor(en color){ enA = color; }
void InA(){cout<<"In A!"<<endl;}
// ** 3 **
{
Base::E();
cout<<"In AE!"<<endl;
}
};
// ** 4 **
{
cout<<"A constructor."<<endl;
}
A::~A()
{
cout<<"A destructor."<<endl;
}
void main()
{
A a1;
a1.E();
cout<<endl;
a1.Print();
a1.InA();
cout<<a1.Getbl()<<endl;
}
第2题:
此题为判断题(对,错)。
第3题:
下列说法正确的有()
A.class中的constructor不可省略
B.constructor必须与class同名,但方法不能与class同名
C.constructor在一个对象被new时执行
D.一个class只能定义一个constructor
第4题:
在Java中,欲定义某类所在的包外的所有类都能访问这个类,则应用的关键字是()。
第5题:
scala中,关于类和函数,以下说法错误是()
第6题:
URL类在______包中定义。
A.java.applet
B.java.io
C.java.net
D.java.util
第7题:
此题为判断题(对,错)。
第8题:
A.class中的constructor不可省略
B.constructor在一个对象被new时执行
C.一个class只能定义一个constructor
D.constructor必须与class同名,但方法不能与class同名
第9题:
下面哪些说明是正确的()
第10题:
Scanner类是在()包中定义的。