C++ 实验题 建立一个楼房基类 Building 为基类

题目:
建立一个楼房基类 Building 为基类,用于存储地址和楼号,建立住宅类 House 继承 Building ,用来存储房号和面积,另外建立办公室类 Ofice 继承 Building ,存储办公室名称和电话号码。

在这里插入代码片#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;
		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("解放东路29号",3);
     building.output();
	house.Houses(308,149);
	house.output();

     building.Buildings("闽南大街31号",4);
      building.output();
	office.Offices("扫黄打非办公室","12390");
	office.output();

	system("pause");
	return 0;
}

在这里插入图片描述

  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值