#include<iostream>
using namespace std;

//class House;

class Room
{
  private:
    char *name;
    int length;
    int width;    
  public:
    Room():length(0),width(0),name("")
    { cout<<"Room::default-arg-ctor\n"; }
    Room(char* rName, int len, int wid)
    {
      cout<<"Room::3-arg-ctor\n";
      name = new char(sizeof(strlen(rName)));
      name = rName;
      length = len;
      width = wid; 
    }
    ~Room(){ 
       cout<<"Room::dtor"<<endl;          
       delete [] name;        
    }
    void disp(){
      cout<< name<<" length :"<<length<<"width : "<<width<<endl;
    }
};

class House
{
  private:
    char* name;
    Room roomsList[3];    
  public:
    House(char *myName) {
      cout<<"House::ctor\n";
      name = new char(sizeof(strlen(myName)));;
      name = myName; 
      roomsList[0] = Room("kitchen", 12, 15);
      roomsList[1] = Room("Bedroom", 24, 30);
      roomsList[2] = Room("TV lounge", 15, 20);
    }
    
    ~House(){
      cout<<"House: dtor"<<endl;       
      delete [] name;
    }

    void disp(){
      cout<<"\n\nName of the House :"<<name;
      unsigned int i;
      cout<<"\n\nRooms details...\n";
      for(i=0; i<3; ++i) 
        roomsList[i].disp();
      cout<<"\n\n";
    } 
};

int main()
{
  cout<<"\nExample of Composition Relationship\n";
  cout<<"-----------------------------------------\n\n";
  {
    House hse("xyz");

    cout<<"\n\nHouse details...\n";
    hse.disp();
  }
  cout<<"Here House itself creates the Rooms and Deletes as well, before it gets deletd...\n";
  system("pause");
}
