CS304 Object Oriented Programming Assignment 3 Solution Fall 2012

You are required to provide a practical implementation in C++ for the following class diagram. You have to provide the solution in the form of classes in C++.

Class Diagram for Assignment No. 3

Figure 1: Object Model of Property Portal

Detail Description:
You are required to give C++ implementation of following classes:

1. PropertyCategories
2. Plot
3. Flat
4. House

Following is the description of all data member and member functions of respective classes:

v Data members for PropertyCategories:

SocietyName: This data member will be used to know the society/town name from where flat, house or plot belongs to.
Area: Total area covered by the plot, flat or house. Area will be in square feet or Marla unit.

v Methods for PropertyCategories:
Constructor(s) and destructor.
Setter and getter function for Area and SocietyName data members.

v Data members for Plot:
PlotNo: A number associated with a plot will be shown to user.

v Methods for Plot:
Constructor(s) and destructor.
Setter and getter function for PlotNo data member.
isPlotAllotted () will ensure whether plot is already allotted or not. If plot is not already allotted to anyone then assign it to current user and make it allotted.
isCornerPlot () will check whether current plot is corner plot or not. You can take input from user in this regard.
isDeveloped () this will ensure that whether plot is in developed status or not. A plot is consider to be developed if, facilities such as electricity, gas, road etc are available, otherwise it will be consider undeveloped plot.

v Data members for Flat
FlatNo: A number associated with a flat will be shown to user.

v Methods for Flat
Constructor(s) and destructor.
Setter and getter function for FlatNo data member.
isOccupied() will check whether this flat is available for rent, selling purpose or not. If anyone is staying in the flat then we can’t rent out or sell this flat.

v Data members for House
HouseNo: A number associated with a house will be shown to user.

v Methods for House
Constructor(s) and destructor for class.
Setter and getter function for HouseNo data member.
isOccupied() will check whether this house is available for rent, selling purpose or not. If anyone is staying in this house then we can’t rent out or sell this house.

Important Points:

You also have to show the relationship (inheritance, association, aggregation, composition) between classes in proper C++ syntax with comments. No marks will be given for incorrect relationship.
Dynamically allocate memory where required.
Implement all member functions of each class. Make sure you use most appropriate return types and signatures for the function.
Implement constructors of all classes (Overload constructors if required also can use copy constructor if required).
Overload and override member functions in classes (if required).

Solution:

/************* assignment no 03 of oops(CS304) ******************/
#include<iostream.h>
#include<conio.h>
class House;
class Room
{
 public: Room() { };
 static void createRoom_v(Room* (&room), House* hse,char* name) { room = new Room(hse, name);
 }
 Room(House* hse, char* myName){
 cout<<"PropertytCategorey";
 myHse_p = hse;
 if(NULL != myHse_p){
 name_p = new char(sizeof(strlen(myName)));
 name_p = myName;
 }
 };
~Room() {
 myHse_p = NULL;
 delete (name_p);
};
 void disp() {
 cout<<"Plot,Flat,House";
 cout<<"isPlotNo,FlatNo,HouseNo";
 cout<<"iscomerPlot(),isOucopied(),isOucopied()";
 cout<<"n";
 }
static void initList_v(Room *(& roomsList_p)[1]){
roomsList_p[1] = new Room[1];
}
private: House * myHse_p;
char * name_p;};
class House{ public: House(char *myName) {
}
~House() {
unsigned int i;
for(i=0; i<3; ++i) {
if(roomsList_p[i] != NULL){
delete (roomsList_p[i]);
 }
 }
delete [] roomsList_p;
delete (name_p);
} void disp(){
cout<<"PropertyCategories:";
if(roomsList_p != NULL) { unsigned int i;
cout<<"nn List of Property Categoreis...n";
for(i=0; i<3; ++i) { if(NULL != roomsList_p[i]) {
 roomsList_p[i]->disp();
}
 }
 cout<<"nn";
 }
 }
 private:
char* name_p;
Room* roomsList_p[3];};
int main(){
 House hse("data members");
 hse.disp();
 cout<<"Select Property Categry..... ";
 getch();
}


DOWNLOAD SOLUTION HERE
loading...