目录
实验目的:
实验任务:
实验内容:
1实验代码
2.运行结果:
实验小结
实验目的:
实验任务:
建立一个楼房基类Building为基类,用于存储地址和楼号,建立住宅类House继承Building,用来存储房号和面积,另外建立办公室类Office继承Building,存储办公室名称和电话号码。基本要求:编制应用程序,建立住宅和办公室对象测试之并输出有关数据提交程序。
实验内容:
1实验代码
#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;
class Building
{
public:
void Buildings(string ad, int h_num)
{
address = ad;
house_num = h_num;
}
void output()
{
cout << "地址为:" << address << endl;
//getline(cin, address);
cout << "楼号为:" << house_num << endl;
}
protected:
string address; //地址
int house_num; //楼号
};
class House :public Building
{
public:
void Houses(int r_num, int ar)
{
room_num = r_num;
area = ar;
}
void output()
{
cout << "房号:" << room_num << endl;
cout << "面积:" << area << "平方米" << endl;
}
protected:
int room_num; //房号
int area; //面积
};
class Office :public Building
{
public:
void Offices(string of_name, string tel)
{
office_name = of_name;
tel_num = tel;
}
void output()
{
cout << "办公室名称:" << office_name << endl;
cout << "电话号码:" << tel_num << endl;
}
protected:
string office_name; //办公室名称
string tel_num; //电话号码
};
int main()
{
Building building;
House house;
Office office;
building.Buildings("风花雪月城", 1010);
building.output();
house.Houses(512, 1024);
house.output();
office.Offices("振华办公室", "924741");
office.output();
system("pause");
return 0;
}
2.运行结果:
实验小结