11-2.cpp

来自「为初学者提供的最佳的C++程序设计源程序库」· C++ 代码 · 共 63 行

CPP
63
字号
#include<iostream.h>
class building
{
protected:
   int floors;
   int rooms;
   double square;
};
class house :public building
{
  int bedrooms;
  int balcony;
public:
  house(int f,int r,double sq,int br,int bal)
  {
    floors=f;
    rooms=r;
    square=sq;
    bedrooms=br;
    balcony=bal;
  }
  void show()
  {
    cout<<"floors:"<<floors<<'\n';
    cout<<"romms:"<<rooms<<'\n';
    cout<<"square measure:"<<square<<'\n';
    cout<<"bedrooms:"<<bedrooms<<'\n';
    cout<<"balcony:"<<balcony<<'\n'; 
	}
  };
class office :public building
{
 int phones;
 int meeting_rooms;
public:
    office(int f,int r,double sq,int p,int mee)
{
   floors=f;
   rooms=r;
   square=sq;
   phones=p;
   meeting_rooms=mee;
 }
void show()
{
  cout<<"floors:"<<floors<<'\n';
  cout<<"rooms:"<<rooms<<'\n';
  cout<<"square measure:"<<square<<'\n';
  cout<<"telephones:"<<phones<<'\n';
  cout<<"meeting_rooms:"<<meeting_rooms<<'\n';
}
};
main()
{
  house hou (6,120,5000,100,80);
  office off(12,80,12000,140,18);
  cout<<"House:\n";
  hou.show();
  cout<<"\n Office:\n";
  off.show();
  return 0;
}

⌨️ 快捷键说明

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