Uploaded by stock hack

SP20 BCS 054 (3)

advertisement
COMSATS University Islamabad Sahiwal Campus
Course
Code:
CSC211
Credit Hours: 4
Course Title:
Algorithms and Data Structures
Lab Instructor:
Semester:
Mr. Ali Usman
Program Name: BS(CS)
3RD
B
08-05-2021
Batch: SP20 Section:
Date:
150 Minutes
30
Maximum Marks:
MUHAMMAD SAJID IQBAL
Reg. No. CUI/SP20-BCS-054/SWL
Time Allowed:
Student’s Name:
Important Instructions / Guidelines:
1. Copied papers will be marked as zero
2. paper submitted after assigned time will not be accepted
3. Paper must include (Name, Roll-no#) otherwise paper will not be accepted.
ANSWER:
CODE :
#include<iostream >
using namespace std;
class bahria_town_lahore
{
private:
struct node
{
string name;
string city;
int blocks;
int sectors;
int streets;
int houses;
node *next;
};
node *head;
public:
bahria_town_lahore()
{head=NULL;
}
void insert_data()
{
if(head==NULL)
{
cout<<"BAHIRA TOWN LAHORE"<<endl;
}
else
{node *ptr;
ptr= head;
node *new_node = new node;
new_node->next = NULL;
cout<<"Enter the name of the society "<<endl;
cin>>new_node->name;
cout<<"Enter the name of the city"<<endl;
cin>>new_node->city;
cout<<"Enter the total number of blocks in the society"<<endl;
cin>>new_node->blocks;
cout<<"Enter the number of sectors"<<endl;
cin>>new_node->sectors;
cout<<"Enter the total number of streets "<<endl;
cin>>new_node->streets;
cout<<"how many houses are there in the street "<<endl;
cin>>new_node->houses;
while(ptr->next!=NULL)
{
ptr = ptr->next;
}
ptr->next = new_node;
}
}
void display()
{
{
int j;
int i;
int k;
node *ptr;
ptr= head;
while(ptr->next!=NULL)
{
ptr = ptr->next;
cout<<ptr->name<<"
"<<ptr->city<<endl;
cout<<"Block A"<<endl;
cout<<"
"<<"Sector A"<<endl;
cout<<"
"<<"Street 1"<<endl;
for( j =1; i<= ptr->houses;i++)
{
cout<<"
"<<"House : "<<"
"<<j<<endl;
}
cout<<"
"<<"Street 2"<<endl;
cout<<"Enter houses for street 2"<<endl;
cin>>ptr->houses;
for( i=j;i<=ptr>houses;i++)
{
cout<<"
"<<"House : "<<" "<<i<<endl;
}
cout<<"
"<<"Sector B"<<endl;
cout<<"
"<<"Street 3"<<endl;
cout<<"Enter houses for street 3"<<endl;
cin>>ptr->houses;
for(int k=i;k<=ptr->houses;k++)
{
cout<<"
"<<"House :
"<<" "<<k<<endl;
}
cout<<"Block B"<<endl;
cout<<"
"<<"Sector C"<<endl;
cout<<"
"<<"Street 4"<<endl;
for( int q =k; q<= ptr->houses;q++)
{
cout<<"
"<<"House : "<<"
"<<q<<endl;
}
cout<<"
"<<"Street 2"<<endl;
cout<<"Enter houses for street 2"<<endl;
cin>>ptr->houses;
for( i=j;i<=ptr>houses;i++)
{
cout<<"
"<<"House : "<<" "<<i<<endl;
}
cout<<"
"<<"Sector B"<<endl;
cout<<"
"<<"Street 3"<<endl;
cout<<"Enter houses for street 3"<<endl;
cin>>ptr->houses;
for(int k=i;k<=ptr->houses;k++)
{
cout<<"
"<<" "<<i<<endl;
}
}
}
}
};
"<<"House :
int main()
{
bahria_town b;
b.insert_data();
b.display();
}
SS :
Download