#include<iostream>
#include<string>
using namespace std;
class House{
private:
string *nameowner;
int *numroom;
int *Rentingfee;
Room *room;
friend class Town;
public:
House(){
setnameowner();
setnumroom();
Rentingfee=new int(0);}
~House(){
cout<<"bye House"<<endl;
delete []room;
}
void setnameowner(){
string a;
cout<<"enter the owner name of this house:";
cin>>a;
nameowner=new string(a);}
const string *getnameowner() const{
return nameowner;}
void setnumroom(){
int b;
cout<<"Enter the rooms number of this house:";
cin>>b;
numroom=new int(b);
setRoom(b);
}
const int *getnumroom()const{
return numroom;}
void setRoom(int n){
room=new Room[n];}
void setRentingFee(int index){
int m;
cout<<"Enter the monthly Renting fee of this house:";
cin>>m;
Rentingfee=new int(m);
}
const int *getRentingFee()const{
return Rentingfee;
}
void DisplayHouse(){
cout<<"the house name is :"<<getnameowner()<<endl;
cout<<"the Renting fee is : "<<getRentingFee()<<endl;
cout<<"the number of rooms in this house is :"<<getnumroom()<<endl;
cout<<"and the rooms details as follows:"<<endl;
for(int i=0;i<*numroom;i++)
room[i].DisplayRoom();}
};
class Town{
private:
House *homes;
bool *Rented;
string *NameTown;
static int Num;
public:
Town(string n ){
setnametown(n);
Rented= new bool [5];
for ( int i=0;i<5;i++){
Rented [i]=0;
sethomes();
Num++;} // end constructor
~Town();
cout<<"bye Town"<<endl;
delete []homes ;
homes=0;} // end destructor
void setnametown( string n ){
cout<<"Enter the name of this Town ::";
cin>>n;
NameTown=new string(n);}
const string *getNameTown() const{
return NameTown;}
int getNum(){
return Num;}
void sethomes(){
homes=new House[5];}
void Addhouse(House a ,int index){
homes[index]=a;
setRented(index);
if( Rented[index]=1)
homes[index]. setRentingFee(index);
else
cout<<"No Rening fee"<<endl;}
void setRented(int index){
IsRented( index);}
void IsRented(int index){
bool a;
cout<<"Is this house with index"<<index<<"rented?? "<<endl;
cout<<"if yes enter 1 else enter 0"<<endl;
cin>>a;
if(a){
Rented[index]=1;
cout<<"this house is rented"<<endl;}
else
cout<<" this house is not rented !"<<endl;
}
void AvgRentFees(){
int sum =0;
for ( int i=0;i<5;i++)
sum+=*(homes[i].Rentingfee);
cout<<"the Average Renting fee is "<<sum/5<<endl;}
void Cheapest(){
int mini=*(homes[0].Rentingfee);
string name=*homes[0].nameowner;
for( int i=0;i<5;i++)
if(mini>*(homes[i].Rentingfee)){
mini=*(homes[i].Rentingfee);
name=*(homes[i].nameowner);}
cout<<"the least renting fee is "<<mini<<"and the name of its owner"<<name<<endl;}
void HomeArea(int index){
int sum=0;
int a=*( homes[index].numroom);
for(int i=0;i<a;i++)
sum+=homes[index].room[i].Area;
cout<<"The Total Area of house index"<<index<<"IS;;"<<sum<<endl;}
void DisplayTowm(){
cout<<"the name of this Town is "<<&getNameTown<<endl;
cout<<"the number of objects in this Town is :"<<getNum()<<endl;
cout<<"this Town includes 5 homes and their info as following :";
for ( int i=0;i<5;i++){
cout<<"info of house "<<i<<" : :";
Addhouse(homes[i],i);
homes[i].DisplayHouse();}
};
class Room{
private:
int Area;
string roomname;
friend class House;
friend class Town;
public:
Room( int a, string n){
setArea(a );
setroomname( n);}
~Room(){
cout<<"bye room"<<endl;}
void setArea(int a){
cout<<"Enter the area of this room ";
cin>>a;
Area=a;}
int getArea(){
return Area;}
void setroomname(string n){
cout<<"Enter the name of this room ";
cin>>n;
roomname=n;}
string getnameroom(){
return roomname;}
void DisplayRoom(){
cout<<"name of room :"<<&getnameroom<<endl;
cout<<"room Area:"<<&getArea<<endl;
}};
void main()
{
Town d("bayan");
}