-
Create objects
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
-
Please read this then edit your post accordingly.
[edit]
And...errrmm... what's your question again?
-
Class building is the base class
All other classes are derived from Building
All I'm trying to to is to and print the derived classes with the values assigned in main thru overloaded constructors
private functions in building are rooms, floors, area and heatype
The derived classes ,addition in this example, school also has as members washrooms, classrooms and offices,
The HTML editor does not seem to want to cooperate.
I appreciate any help