How Can we Put this in the Following Program? In the main function, after creating the Society object and before society.display(), set the owner names of a few houses, and make sure that society.display() displays this information. The main function will look like this: Pic 1 to Pic 2.... Program: //header file #include //using namespace using namespace std; char block_number = 'A'; char sector_number = 'A'; int street_number = 1; int house_number = 1; class house{ public: int name; house * next; house(int n){ name = n; next = NULL; } void display(){ cout<<"\t\t\t\tHouse "<next = t2; temp = temp->next; } return ret; } class street{ public: int name; street * next; int no_of_houses; house * head; street(int n){ int n_h; name = n; next = NULL; //dispaly the houses in street cout<<"\nEnter number of houses in street "+to_string(n)+"\t"; cin>>n_h; no_of_houses = n_h; head = initialize_houses(n_h); } void display(){ cout<<"\t\t\tStreet "<display(); temp = temp->next; } } }; street * initialize_streets(int n_strt){ street * ret = new street((street_number)); street_number++; street * temp = ret , * t2; for(int j=1;jnext = t2; temp = temp->next; } return ret; } class sector{ public: string name; sector * next; int no_of_streets; street * head; sector(string n){ int n_strt; name = n; next = NULL; //display the streets in sector cout<<"\nEnter number of streets in sector "+n+" \t"; cin>>n_strt; no_of_streets = n_strt; head = initialize_streets(n_strt); } void display(){ cout<<"\t\tSector "<display(); temp = temp->next; } } }; sector * initialize_sectors(int n_sec){ string send=""; sector * ret = new sector(send+sector_number); sector_number++; sector * temp = ret , * t2; for(int j=1;jnext = t2; temp = temp->next; } return ret; } class block{ public: string name; block * next; int no_of_sectors; sector * head; block(string n){ int n_sec; name = n; next = NULL; //display the sectors in block cout<<"\nEnter number of sectors in block "+n+"\t"; cin>>n_sec; no_of_sectors = n_sec; head = initialize_sectors(n_sec); } void display(){ cout<<"\tBlock "<display(); temp = temp->next; } } }; block * initialize_blocks(int n_b){ string send=""; block * ret = new block(send+block_number); block_number++; block * temp = ret , * t2; for(int j=1;jnext = t2; temp = temp->next; } return ret; } class Society{ public: string name,city; int no_of_blocks; block * head; Society(){ string n,c; int n_b; //display the society name cout<<"Enter the name of society\t"; getline(cin,n); //display the city name cout<<"\nEnter the name of city\t"; getline(cin,c); name = n; city = c; //display the society cout<<"\nEnter number of blocks in society\t"; cin>>n_b; no_of_blocks = n_b; head = initialize_blocks(n_b); } void display(){ cout<display(); temp = temp->next; } } }; //main function int main(){ Society society; society.display(); //returning the value return 0; }
How Can we Put this in the Following Program?
In the main function, after creating the Society object and before society.display(), set the owner names of a few houses, and make sure that society.display() displays this information. The main function will look like this:
Pic 1 to Pic 2....
Program:
//header file
#include<bits/stdc++.h>
//using namespace
using namespace std;
char block_number = 'A';
char sector_number = 'A';
int street_number = 1;
int house_number = 1;
class house{
public:
int name;
house * next;
house(int n){
name = n;
next = NULL;
}
void display(){
cout<<"\t\t\t\tHouse "<<name<<endl;
}
};
house * initialize_houses(int n_h){
house * ret = new house((house_number));
house_number++;
house * temp = ret , * t2;
for(int j=1;j<n_h;j++){
t2 = new house((house_number));
house_number++;
temp->next = t2;
temp = temp->next;
}
return ret;
}
class street{
public:
int name;
street * next;
int no_of_houses;
house * head;
street(int n){
int n_h;
name = n;
next = NULL;
//dispaly the houses in street
cout<<"\nEnter number of houses in street "+to_string(n)+"\t";
cin>>n_h;
no_of_houses = n_h;
head = initialize_houses(n_h);
}
void display(){
cout<<"\t\t\tStreet "<<name<<endl;
house * temp = head;
while(temp!=NULL){
temp->display();
temp = temp->next;
}
}
};
street * initialize_streets(int n_strt){
street * ret = new street((street_number));
street_number++;
street * temp = ret , * t2;
for(int j=1;j<n_strt;j++){
t2 = new street((street_number));
street_number++;
temp->next = t2;
temp = temp->next;
}
return ret;
}
class sector{
public:
string name;
sector * next;
int no_of_streets;
street * head;
sector(string n){
int n_strt;
name = n;
next = NULL;
//display the streets in sector
cout<<"\nEnter number of streets in sector "+n+" \t";
cin>>n_strt;
no_of_streets = n_strt;
head = initialize_streets(n_strt);
}
void display(){
cout<<"\t\tSector "<<name<<endl;
street * temp = head;
while(temp!=NULL){
temp->display();
temp = temp->next;
}
}
};
sector * initialize_sectors(int n_sec){
string send="";
sector * ret = new sector(send+sector_number);
sector_number++;
sector * temp = ret , * t2;
for(int j=1;j<n_sec;j++){
string send="";
t2 = new sector(send+sector_number);
sector_number++;
temp->next = t2;
temp = temp->next;
}
return ret;
}
class block{
public:
string name;
block * next;
int no_of_sectors;
sector * head;
block(string n){
int n_sec;
name = n;
next = NULL;
//display the sectors in block
cout<<"\nEnter number of sectors in block "+n+"\t";
cin>>n_sec;
no_of_sectors = n_sec;
head = initialize_sectors(n_sec);
}
void display(){
cout<<"\tBlock "<<name<<endl;
sector * temp = head;
while(temp!=NULL){
temp->display();
temp = temp->next;
}
}
};
block * initialize_blocks(int n_b){
string send="";
block * ret = new block(send+block_number);
block_number++;
block * temp = ret , * t2;
for(int j=1;j<n_b;j++){
string send="";
t2 = new block(send+block_number);
block_number++;
temp->next = t2;
temp = temp->next;
}
return ret;
}
class Society{
public:
string name,city;
int no_of_blocks;
block * head;
Society(){
string n,c;
int n_b;
//display the society name
cout<<"Enter the name of society\t";
getline(cin,n);
//display the city name
cout<<"\nEnter the name of city\t";
getline(cin,c);
name = n;
city = c;
//display the society
cout<<"\nEnter number of blocks in society\t";
cin>>n_b;
no_of_blocks = n_b;
head = initialize_blocks(n_b);
}
void display(){
cout<<name<<"\t"<<city<<endl;
block * temp = head;
while(temp!=NULL){
temp->display();
temp = temp->next;
}
}
};
//main function
int main(){
Society society;
society.display();
//returning the value
return 0;
}
Step by step
Solved in 3 steps with 6 images