/*
* room.cpp
*
* Created on: 21/10/2010
* Author: User
*/
#include <iostream>
#include <string>
usingnamespace std;
//declaration section
class room
{
private:
int rmLength;
int rmWidth;
string colour;
public:
room (int = 5, int = 4, string = "green");
int calArea ();
void printArea ();
~ room ();
};
room::room(int rmL, int rmW, string col)
{
rmLength = rmL;
rmWidth = rmW;
colour = col;
}
void room::printArea()
{
cout << "Area of Room A is " << calArea() << " come in " << colour << " colour" << endl;
}
int room::calArea()
{
int calArea;
calArea = rmLength * rmWidth;
return calArea;
}
room::~room()
{
cout << "Room Destroyed!" << endl;
}
int main ()
{
room rooma, roomb (4, 4, "white");
rooma.printArea();
roomb.printArea();
return 0;
}
Basically it's a simple console program that will print out the room area & colour.
1 2 3 4
Area of Room A is 20 come in green colour
Area of Room A is 16 come in white colour
Room Destroyed!
Room Destroyed!
However, I would like the room name to change to Room B for the second line.
Also my destructor seem to be printing out two times. Anyway to resolve this.
// Well as for the making Room B, couldn't you make say a char roomLetter = 'A';
and then change roomLetter = 'B'; at a certain point in there?
// It would definitely have to be something like cout << "Area of Room " << roomLetter << " is " << calArea() right? That's what filipe meant by not hard-coding it I believe.
// What filipe said also makes sense and what I was sort of wondering. Though shouldn't it destruct after each Room output? Instead of having two "Room Destroyed!" next to each other, should it be in between? Totally unsure!