⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 13-2.cpp

📁 为初学者提供的最佳的C++程序设计源程序库
💻 CPP
字号:
#include<iostream.h>
#include<iomanip.h>
#include<string.h>
class Building
{
protected:
   int sqMe;
char addr[25];
public:
  Building(int,char[]);
  void print(void);
};
Building::Building(int S,char A[]):sqMe(S)
{
   strcpy(addr,A);
}
void Building::print(void)
{
   cout<<"The building has"<<sqMe<<"square metre\n";
   cout<<"The building's address is"<<addr<<".\n\n";
}
class Shed:public Building
{
  char useCode;
public:
   Shed(int,char[],char);
};
Shed::Shed(int S,char A[],char U):Building(S,A),useCode(U)
{}
class House:public Building
{
  int numRooms;
  float cost;
public:
  House(int,char[],int,float);
  void print(void);
};
House::House(int S,char A[],int N,float C):Building(S,A),
       numRooms(N),cost(C)
{}
void House::print(void)
{
  cout<<"The house has"<<sqMe<<"square metre.\n";
  cout<<"The house address is"<<addr<<".\n";
  cout<<"The house has"<<numRooms<<"number of rooms.\n";
  cout<<"The house cost"<<cost<<".\n\n";
}
class Office:public Building
{
  int zoneCode;
  float rent;
public:
  Office(int,char[],int,float);
  void print(void);
};
Office::Office(int S,char A[],int Z,float R):Building(S,A),
        zoneCode(Z),rent(R)
{}
void Office::print(void)
{
  cout<<"The office has"<<sqMe<<"square metre.\n";
  cout<<"The office address is"<<addr<<".\n\n";
  cout<<"The office is zoned for"<<zoneCode<<"code.\n";
  cout<<"The office rents for"<<rent<<".\n\n";
}
main()
{
 Building *pro[3];
 Shed aShed=Shed(102,"Beijing",'x');
 House aHouse=House(360,"Chengdu",9,5800.00);
 Office anOffice=Office(980,"Guilin",'B',780.45);
 pro[0]=&aShed;
 pro[1]=&aHouse;
 pro[2]=&anOffice;
 for(int ctr=0;ctr<3;ctr++)
 {
   pro[ctr]->print();
 }
  delete pro[0];
  delete pro[1];
  delete pro[2];
  return 0;
}

⌨️ 快捷键说明

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