Code://base class building definition. #ifndef BUILDING_H #define BUILDING_H #include <iostream.h> class building { public: building(); //default constructor building(int r, int fl, int fla, char h); //overloaded construtor ~building(); //destructor void printoscreen(); //prints to screen void setrooms (int numrooms); //set no. rooms int getrooms(); //get no. rooms void setfloors (int numfloors); //set no. floors int getfloors(); //get no.of floors void setarea (int floorarea); //set floorarea int getarea(); //get floorarea void setheat (char heatype); //set heatertype int getheat(); //get heatertype private: int rooms; int floors; int area; char heatype; }; #endif // member function definition for class building #include "building.h" building::building() { // NULL constructor rooms=0; floors=0; area=0; heatype='o'; } //constructor function to initialize private data building::building(int r, int f, int fla, char ht) { rooms = r; floors = f; area = fla; heatype = ht; } building::~building() // call destructor { cout<<"\nThe building object has been destroyed"; } void building::printoscreen(){ // print data to screen cout<<"\nThe number of rooms = :"<<getrooms(); cout<<"\nThe number of floors = :"<<getfloors(); cout<<"\nThe floor area of the building is : "<<getarea()<<" square feet"; if(getheat() == 'o') cout<<"\nHeating type is Oil."; else cout<<"\nHeating type is Electric."; } //mutator functions void building::setrooms(int numrooms){ // set the number of rooms rooms =numrooms; } void building::setfloors(int numfloors){ floors =numfloors; } void building::setarea(int farea) { // set floorarea area = farea; } void building::setheat(char heatr) { // set heater heatype = heatr; } // accessor functions int building::getrooms() { return rooms; } int building::getfloors() { return floors; } int building::getarea() { return area; } int building::getheat() { return heatype; } // member function definition for class building #include "building.h" building::building() { // NULL constructor rooms=0; floors=0; area=0; heatype='o'; } //constructor function to initialize private data building::building(int r, int f, int fla, char ht) { rooms = r; floors = f; area = fla; heatype = ht; } building::~building() // call destructor { cout<<"\nThe building object has been destroyed"; } void building::printoscreen(){ // print data to screen cout<<"\nThe number of rooms = :"<<getrooms(); cout<<"\nThe number of floors = :"<<getfloors(); cout<<"\nThe floor area of the building is : "<<getarea()<<" square feet"; if(getheat() == 'o') cout<<"\nHeating type is Oil."; else cout<<"\nHeating type is Electric."; } //mutator functions void building::setrooms(int numrooms){ // set the number of rooms rooms =numrooms; } void building::setfloors(int numfloors){ floors =numfloors; } void building::setarea(int farea) { // set floorarea area = farea; } void building::setheat(char heatr) { // set heater heatype = heatr; } // accessor functions int building::getrooms() { return rooms; } int building::getfloors() { return floors; } int building::getarea() { return area; } int building::getheat() { return heatype; } // driver for building #include "building.h" #include "business.h" #include "school.h" #include "home.h" int main(void) { building b(20, 3, 18000, 'o') ; //building parameter is 20 rooms, 3 floors, //18000sqfeet and oil heat b.printoscreen(); school s(75, 2, 55000, 'o', 10, 40, 12); //derived object s of class school //building set to 75 rooms, 2 floors, s.printoscreen(); //55000sqfeet and has oil heat //derived business class parameters business bus(20, 1, 21000, 'o', 4, 12); bus.printoscreen(); //derived class home parameters home h(11, 3, 12000, 'e', 2, 5); h.printoscreen(); return 0; }
Code tags added by Hammer