Welcome to Home.

Saturday, December 6, 2014

Array of Structures

:Structure is used to store the information of One particular object but if we need to store such 100 objects then Array of Structure is used.

#include<iostream.h>
#include<conio.h>
struct passenger
{
int ticket_no;
char name[10];
char address[10];
int phone_no;
char source[10];
char destination[10];
};
class agency
{
public:
passenger p[20];
int count;
void add_passenger()
{
count=0;
cout<<"\nEnter passenger ticket number:";
cin>>p[count].ticket_no;
cout<<"\nEnter passenger name:";
cin>>p[count].name;
cout<<"\nEnter passenger address:";
cin>>p[count].address;
cout<<"\nEnter passenger phone number:";
cin>>p[count].phone_no;
cout<<"\nEnter source:";
cin>>p[count].source;
cout<<"\nEnter destination:";
cin>>p[count].destination;
count++;
}

void search_passenger()
{
int t;
cout<<"\nEnter ticket number:";
cin>>t;
for(int k=0;k<20;k++)
{
if(p[k].ticket_no==t)
{
cout<<"Name:"<<p[k].name<<endl;
cout<<"Address:"<<p[k].address<<endl;
cout<<"Phone Number:"<<p[k].phone_no<<endl;
cout<<"Source:"<<p[k].source<<endl;
cout<<"Destination:"<<p[k].destination;
break;
}
}
}
};
void main()
{
agency obj;
int choice;
char n='n';
clrscr();
line:
cout<<"\n1.Add Passenger\n";
cout<<"2.Search Passenger\n";
cout<<"Enter:";
cin>>choice;
if(choice==1)
obj.add_passenger();
   clrscr();
if(choice==2)
obj.search_passenger();
else
cout<<"Thanks";
cout<<"Do u wanna continue?(y/n)";
cin>>n;
if(n=='y')
goto line;
else
cout<<"Visit Again";
getch();
}


No comments:

Post a Comment