求C++高手帮忙

来源:百度知道 编辑:UC知道 时间:2024/07/16 15:54:27
创建一个Employee类,该类中有字符数组,用于表示街道地址、市、省和邮政编码;该类中还含有Name类的一个对象(Name类中,定义名和姓为保护数据成员,其构造函数为接受一个指向完整姓名字符串的指针,其Display函数输出姓名);Employee类定义中还包括构造函数、ChangeName( )、Display( )。构造函数初始化每个成员,Display( )函数把完整的对象数据打印出来,ChangeName( )用于修改Name对象值。其中的数据成员是保护的,函数成员是公共的。

可以参考一下
#include <iostream>
using namespace std;

class building{
int cengshu;
int fangjian;
int mianji;
public:
building(int a=0, int b=0, int c=0):cengshu(a),fangjian(b),mianji(c){};
};

class house:public building{
int woshi;
int yushi;
public:
house(int a=0, int b=0, int d=0, int e=0, int f=0):woshi(a),yushi(b),building(d,e,f){};
void show();
};

void house::show(){
cout<<"房间:"<<endl<<" 卧室:"<<woshi<<endl<<" 浴室:"<<yushi<<endl;

}

class office :public building{
int miehuoqi;
int dianhua;
public:
office(int a=0, int b=0, int d=0, int e=0, int f=0):miehuoqi(a),dianhua(b),building(d,e,f){};
void show();
};

void office::show(){
cout<<"办公室:"<<endl<<" 灭火器:"<<miehuoqi<<endl