test3.1_inherittestone.cpp

来自「定义并实现复数类」· C++ 代码 · 共 61 行

CPP
61
字号
/*#include<iostream>
using namespace std;
class building
{
protected:
	int floors,rooms,square;
public:
	building(int floors,int rooms,int square)
	{
		this->floors=floors;
		this->rooms=rooms;
		this->square=square;
	}
	void showBuilding()
	{
		cout<<"Building:"<<"floors="<<floors<<",rooms="<<rooms<<",square"<<square<<endl;
	}
};
class house:public building
{
private:
	int bedroom,bathroom;
public:
	house(int floors,int rooms,int square,int bedroom,int bathroom):building(floors,rooms,square)
	{		
		this->bedroom=bedroom;
		this->bathroom=bathroom;
	}
	void showHouse()
	{
        cout<<"House: "<<"floors="<<floors<<",rooms="<<rooms<<",square"<<square<<",bedroom="<<bedroom
			<<",bathroom="<<bathroom<<endl;
	}
};
class office:public building
{
private:
	int fire_extinguisher,telephone;
public:
	office(int floors,int rooms,int square,int fire_extinguisher,int telephone):
	building(floors,rooms,square)
	{
		
		this->fire_extinguisher=fire_extinguisher;
		this->telephone=telephone;
	}
	void showOffice()
	{
		cout<<"Office: "<<"floors="<<floors<<",rooms="<<rooms<<",square"<<square
			<<",fire_extinguisher="<<fire_extinguisher<<",telephone="<<telephone<<endl;
	}
};
void main()
{
	building build(1,2,3);
	build.showBuilding();
	house hou(2,3,4,5,6);
	hou.showHouse();
	office off(3,4,5,6,7);
	off.showOffice();
}*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?