Home > Back-end >  8. To design a kind of Building, Building to derive from it the Building called the - Building and d
8. To design a kind of Building, Building to derive from it the Building called the - Building and d

Time:09-27

#include
Using namespace STD.
The class Building
{
Public:
C Building (int n, int, int r, float a)
{
Num=n;
Cen=c;
Room=r;
Area=a;
}
Void the display ()
{
cout<& lt;" Number: "& lt; }
Protected:
Int num.//number
Int cen.//layer
Int the room;//room number
Float area;//total area
};

Class TeachBuilding: public Building//Building
{
Public:
TeachBuilding (int int n, int a, c, e, r, float a, int cr) : Building (n, c, r, a)//to call the superclass constructor
{
Cr=classroom;//to perform their own constructor
}
Void display1 ()
{
Building: the display ();
cout<& lt;" The classroom number: "& lt; }
Protected:
Int classroom;//the classroom number
};
The class DormBuilding: public Building//dormitory
{
Public:
DormBuilding (int int n, int a, c, e, r, float a, int dc, int DSC) : Building (n, c, r, a)//to call the superclass constructor
{
Dc dormcount;
DSC=dormsum_count;//to perform their function body
}
Void display2 ()
{
Building: the display ();
cout<& lt;" Dormitory: "& lt; cout<& lt;" Dormitory: total "& lt; }
Protected:
Int dormcount;//dorm number
Int dormsum_count;//let the total number of dormitory
};
Int main ()
{
TeachBuilding a,60,600,2000,100 (10);
A. d. isplay1 ();
,33,500,4300,100,400 DormBuilding b (12);
B.d isplay2 ();
return 0;
}
Why turn output data members of the derived class will output error??????? In vs shows insufficient resources cannot run??

CodePudding user response:

The assignment given the
Cr=classroom;//to perform their own constructor
Here should be classroom=cr
The following a derived class in the same way
  • Related