C++类实现公有继承

#include<iostream>
using namespace std;
class Building{
	public:
	void get_value()
	{
		cout<<"Input   floor_num ,room_num  ,total_Area  "<<endl;
		cin>>floor_num>>room_num>>total_Area;
	}
	void display()
	{
		cout<<"floor_num :"<<floor_num<<endl;
		cout<<"room_num:"<<room_num<<endl;
		cout<<"total_Area:"<<total_Area<<endl;
	}
	private :
	int floor_num ,room_num ; 
	double total_Area;
};
class House : private Building{
public:
void get_value1()
{
	get_value();
	cout<<"Input bedroom_num, bathroom_num"<<endl;
	cin>>bedroom_num>>bathroom_num;
}
void display1()
{
	display();   //在继承类内调用基类的公有函数操作基类的私有变量
	cout<<"bedroom_num:"<<bedroom_num<<endl;
	cout<<"bathroom_num:"<<bathroom_num<<endl;
}
	private :
	int bedroom_num, bathroom_num;
};
class Office: private Building{
	public:
	void get_value2()
	{
		get_value();
		cout<<"Input fire_num, telephone_num"<<endl;
		cin>>fire_num>>telephone_num;
	}
	void display2()
	{
		display();
		cout<<"fire_num:"<<fire_num<<endl;
		cout<<"telephone_num"<<telephone_num<<endl;
	}
	private:
	int fire_num, telephone_num;
};
int main()
{
	House house;
	house.get_value1();
	house.display1();
	Office office;
	office.get_value2();
	office.display2();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值