/*
* 实验四:继承性和派生类
* 内容提要:建立一个楼房基类Building为基类,用于存储地址和楼号
* 建立住宅类House继承Building, 用来存储房号和面积,
* 另外建立办公室类Office继承Building, 存储办公室名称和电话号码。
* 基本要求:编制应用程序,建立住宅和办公室对象测试之并输出有关数据
*/
/*
* 实验四:继承性和派生类
* 内容提要:建立一个楼房基类Building为基类,用于存储地址和楼号
* 建立住宅类House继承Building, 用来存储房号和面积,
* 另外建立办公室类Office继承Building, 存储办公室名称和电话号码。
* 基本要求:编制应用程序,建立住宅和办公室对象测试之并输出有关数据
*/
#include <iostream>
#include <cstring>
using namespace std;
class Building {
public:
string adress;
string buildingNo;
};
class House : public Building {
public:
string roomNumber;
double area = 0;
};
class Office : public Building {
public:
string officeName;
string telNumber;
};
int main() {
House house;
string house_adress; //住宅地址
string house_buildingNo; //住宅楼号
string house_roomNumber; //住宅房号
double house_area; //住宅面积
Office office;
string office_adress; //办公室地址
string office_buildingNo;//办公室楼号
string office_officeName;//办公室名字
string office_telNumber;//办公室电话
cout << "请输入住宅地址:" << endl;
cin >> house_adress;
house.adress = house_adress;
cout << "请输入住宅楼号:" << endl;
cin >> house_buildingNo;
house.buildingNo = house_buildingNo;
cout << "请输入住宅房号:" << endl;
cin >> house_roomNumber;
house.roomNumber = house_roomNumber;
cout << "请输入住宅面积:" << endl;
cin >> house_area;
house.area = house_area;
cout << "这个住宅的地址为:" << house.adress << ", 它的楼号为:" << house.buildingNo
<< ", 房号是:" << house.roomNumber << ", 它有" << house.area << "平方米。" << endl << endl;
cout << "请输入办公室地址:" << endl;
cin >> office_adress;
office.adress = office_adress;
cout << "请输入办公室楼号:" << endl;
cin >> office_buildingNo;
office.buildingNo = office_buildingNo;
cout << "请输入办公室名字:" << endl;
cin >> office_officeName;
office.officeName = office_officeName;
cout << "请输入办公室电话:" << endl;
cin >> office_telNumber;
office.telNumber = office_telNumber;
cout << "这个办公室的地址为:" << office.adress << ", 它的楼号是:" << office.buildingNo
<< ", 办公室的名字是:" << office.officeName << ", 办公室的电话是:" << office.telNumber << endl << endl;
system("pause");
return 0;
}