使用VC++6.0打开考生文件夹下的源程序文件3.cpp。其中定义的类不完整,按要求完成下列操作,将类的定义补充完整。
(1)基类People完成打印功能,定义其中的打印函数为虚函数,请在注释1后添加适当的语句。
(2)类Boy继承于People,在构造函数中设置性别为1,请在注释2后添加适当的语句。
(3)类Girl继承于People,在构造函数中设置性别为0,请在注释3后添加适当的语句。
(4)实现函数fun,用于传递不同的类型,打印出性别,请在注释4后添加适当的语句。
输出的内容如下:
Sex=Boy
Sex=Girl
注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。
试题程序:
#include<iostream.h>
class People
public:
//********1********
void print()
int sex;
;
class Boy:public People
public:
Boy()
//********2********
void print()
cout<<"Boy"<<end1;
;
class Girl:public People
public:
Girl()
//********3********
void print()
cout<<"Girl"<<end1;
;
//********&********
eout<<"Sex=";
p.print();
int main()
Boy m;
fun(m);
Girl n;
fun(n);
return 0;