面向对象编程技术(作业题一)

#include <iostream>

using namespace std;

class Building
{
protected:
 int m_nFloorNum;  // 层数
 int m_nRoomNum;   // 房间数
 int m_nArea;   // 总平方米数

public:
 Building()
 {
  m_nFloorNum = 0;
  m_nRoomNum = 0;
  m_nArea = 0;
 }

 Building(int nFloorNum, int nRoomNum, int nArea)
 {
  m_nFloorNum = nFloorNum;
  m_nRoomNum = nRoomNum;
  m_nArea = nArea;
 }

 virtual ~Building()
 {
 }

 void OutputInfo()
 {
  cout<<"层数:"<<m_nFloorNum<<endl;
  cout<<"房间数:"<<m_nRoomNum<<endl;
  cout<<"总平方米数:"<<m_nArea<<endl;
 }
};

class House : public Building
{
protected:
 int m_nBedroomNum;  // 卧室数
 int m_nBathroomNum;  // 浴室数

public:
 House()
 {
  m_nBedroomNum = 0;
  m_nBathroomNum = 0;
 }

 House(int nFloorNum, int nRoomNum, int nArea, int nBedroomNum, int nBathroomNum)
  : Building(nFloorNum, nRoomNum, nArea)
 {
  m_nBedroomNum = nBedroomNum;
  m_nBathroomNum = nBathroomNum;
 }

 virtual ~House()
 {
 }

 void OutputInfo()
 {
  Building::OutputInfo();
  cout<<"卧室数:"<<m_nBedroomNum<<endl;
  cout<<"浴室数:"<<m_nBathroomNum<<endl;
 }
};

class Office : public Building
{
protected:
 int m_nDeskNum;   // 办公桌数
 int m_nPhoneNum;  // 电话数

public:
 Office()
 {
  m_nDeskNum = 0;
  m_nPhoneNum = 0;
 }

 Office(int nFloorNum, int nRoomNum, int nArea, int nDeskNum, int nPhoneNum)
  : Building(nFloorNum, nRoomNum, nArea)
 {
  m_nDeskNum = nDeskNum;
  m_nPhoneNum = nPhoneNum;
 }

 virtual ~Office()
 {
 }

 virtual void OutputInfo()
 {
  Building::OutputInfo();
  cout<<"办公桌数:"<<m_nDeskNum<<endl;
  cout<<"电话数:"<<m_nPhoneNum<<endl;
 }
};

///
int main(int argc, char* argv[])
{
 House house1;
 house1.OutputInfo();
 cout<<endl;

 House house2(7, 28, 2800, 84, 28);
 house2.OutputInfo();
 cout<<endl;

 Office office1;
 office1.OutputInfo();
 cout<<endl;

 Office office2(3, 12, 1200, 36, 36);
 office2.OutputInfo();
 cout<<endl;

 return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值