Wednesday, June 15, 2011
(Attock VU Group) CS304 (ZERO ERROR) Assignment 3 Solution
#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<<"\nPakistaniCitizens";
myHse_p=hse;
if(NULL!=myHse_p)
{
name_p= new char(sizeof(strlen(myName)));
name_p = myName;
}
else
{
cout<<"\nPlease enter the age of the citizen";
}
};
~Room()
{
cout<<"\nPakistaniCitizens";
myHse_p=NULL;
delete (name_p);
};
void disp()
{
cout<<name_p;
cout<<"\n";
}
static void initList_v(Room*(& roomsList_p)[3])
{
roomsList_p[3]=new Room[3];
}
private:House*myHse_p;
char*name_p;
};
class House{ public:House(char *myName)
{
cout<<"\n PakistaniCitizens \n";
name_p = new char(sizeof(strlen(myName)));;
name_p = myName;
Room::initList_v(roomsList_p);
Room*myRoom;
Room::createRoom_v(myRoom, this, "name");
roomsList_p[0] = myRoom;
Room::createRoom_v(myRoom, this, "age");
roomsList_p[1] = myRoom;
Room::createRoom_v(myRoom, this, "CNIC No");
roomsList_p[2] = myRoom;
}
~House()
{
cout<<"PakistaniCitizens\n";
unsigned int i;
cout<<"Eligible for vote cast...\n";
for(i=0; i<3; ++i)
{
if(roomsList_p[i] != NULL)
{ delete (roomsList_p[i]);
} }
delete [] roomsList_p;
delete (name_p);
} void disp()
{ cout<<"\n\nPakistaniCitizens :"<<name_p;
if(roomsList_p != NULL) { unsigned int i;
cout<<"\n\nVotersList...\n";
for(i=0; i<3; ++i) { if(NULL != roomsList_p[i])
{
roomsList_p[i]->disp();
}
}
cout<<"\n\n";
}
}
private:
char*name_p;
Room*roomsList_p[3];
};
int main()
{ cout<<"\nExample of Composition Relationship\n";
cout<<"-----------------------------------------\n\n";
House hse("data members"
);
cout<<"\n\nPakistaniCitizens...\n";
hse.disp();
cout<<"Age is less than 18...\n";
return(0);
}
--
Family and Friends are hidden treasures,
seek them and enjoy their riches
By: -
insomniac.dude @ skype
--
Group Basic Rules:
Immoral & Rudish talk, Earning program links, Cell number for friendship purpose, Websites/Groups Links, Adult contents, Spamming are strictly prohibited and banned in group.
Follow these detailed Group Rules, otherwise you will be banned at any time.
https://docs.google.com/document/d/1YJxA8x3_U7C1lRc0EXfLrJpco4A1XkB1vDxOTqOd3Jg/edit?hl=en&authkey=CNDy9tkJ
Group Email Address:
Attock-VU-Group@Googlegroups.Com
Join group by sending a blank email from University ID at:
Attock-VU-Group+Subscribe@Googlegroups.Com
Click here to Join this group at Facebook:
https://www.facebook.com/home.php?sk=group_111877855568034
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment