Monday, 17 October 2011

RAILWAY RESERVATION SYSTEM


PROGRAM:
//RAILWAY RESERVATION SYSTEM
#include<iostream.h>                       //including header files
#include<string.h>
#include<conio.h>
long int gl=2545;
class admin
{
          public:
                   int tr_no,seats,cost1,cost2,cost3;
                   char tr_name[50],b[50],d[50];           //data members
          public:
                   admin()
                   {
                   }
          admin(int t,int s,char n[],char bp[],char dp[],int c1,int c2,int c3)            //parameterised constructor
                   {
                   tr_no=t;
                   seats=s;
                   strcpy(tr_name,n);
                   strcpy(b,bp);
                   strcpy(d,dp);
                   cost1=c1;
                   cost2=c2;
                   cost3=c3;
                   }
                    void display()                                          //display function
                   {
                    cout<<tr_no<<"\t"<<seats<<"\t"<<tr_name<<"\t"<<b<<"\t"<<d<<"\t"<<cost1<<"\t"<<cost2<<"\t"<<cost3<<"\n";
                   }
};
class passenger:public admin          //derived class inherited publicly
{
          public:
          int age,pas,clas,cost,pnr,status;
          char pasname[50];
          public:
                   passenger()
                   {
                   }
                   passenger(int a,int b,char c[],char d[],char e[],int f,int g,int h):admin(a,b,c,d,e,f,g,h)         //parameterized constructor
                   {

                   }
                   passenger(char a[],int b,int c,int x)
                   {
                             strcpy(pasname,a);
                             age=b;
                             clas=c;
                             pnr=gl+x;
                   }
                   void reserve(int a,int b,passenger *p,passenger common)
                   {
                             common.cost=0;
                             if(b==1)
                             {
                                      cost=p[a].cost1;      //assigning individual cost for each passenger
                             }
                             if(b==2)
                             {
                                      cost=p[a].cost2;
                             }
                             if(b==3)
                             {
                                      cost=p[a].cost3;
                             }
                   }
                   void calc(passenger common)
                   {
                             common.cost=common.cost+cost;
                   }
                   void display1(int a,passenger *p)
                   {
                             cout<<"\n - "<<p[a].tr_no<<"\t\t"<<p[a].tr_name<<"\t\t"<<p[a].b<<"\t\t"<<p[a].d<<"\t"<<pnr<<"\t -";
                   }
                   void display2(int o)
                   {
                             status=o;
                             if(o==1)
                             {
                             cout<<"\n - "<<pasname<<"\t"<<age<<"\t"<<cost<<"\t\t\t\t\t"<<"CONFIRMED"<<"\t -";
                             }
                             else
                             {
                             cout<<"\n - "<<pasname<<"\t"<<age<<"\t"<<cost<<"\t\t\t\t\t"<<"WL"<<"\t -";
                             }
                   }
                   void display3()
                   {
                             cout<<"\n -Total cost \t\t\t\t:\t"<<cost;
                   }

};
int main()
{
          clrscr();
          passenger p[10],common,pas[10],wait[10];
          int n,i,st,trainno,co1,co2,co3,ch,se,seats2,seats3,cho,page,seats,choice2,flag=0,set=0,pn=0,j,cl,seats1;
          char name[50],bo[50],dp[50],pname[50];
          cout<<"\n\t\t <<<***   SKCET RAILWAYS   ***>>>\n";
          cout<<"\tWELCOME ADMINISTRATOR\n";
          cout<<"Enter the total number of trains";
          cin>>n;
          //p=new passenger[n];
          for(i=1;i<=n;i++)
          {
                   cout<<"\nEnter the details for train "<<i<<"\n";
                   cout<<"\nEnter name\t:";
                   cin>>name;
                   cout<<"\nEnter train no\t:";
                   cin>>trainno;
                   cout<<"\nEnter boarding place\t:";
                   cin>>bo;
                   cout<<"\nEnter destination place\t:";
                   cin>>dp;
                   cout<<"\nEnter the number of seats available\t:";
                   cin>>st;
                   cout<<"\nEnter cost per head for I class\t:";
                   cin>>co1;
                   cout<<"\nEnter cost per head for II class\t:";
                   cin>>co2;
                   cout<<"\nEnter cost per head for III class\t:";
                   cin>>co3;
          //        p[i]=passanger(trainno,st);
           //       p[i]=passenger(i);
                    p[i]=passenger(trainno,st,name,bo,dp,co1,co2,co3);
          }
                    cout<<"\nTrain no\tSeats\tName\tBoarding\tDestination\tcostI\tcostII\tcostIII\n";
                   for(i=1;i<=n;i++)
                    {
                             p[i].display();
                    }
                    do
                   {
                             cout<<"\n1.ADMINSTRATOR\n2.PASSENGER";
                             cin>>ch;
                             switch (ch)
                             {
                              case 1:
                                      {
                                      cout<<"\nCURRENT TRAIN STATUS\n";
                                      cout<<"\nTrain no\tSeats\tName\tBoarding\tDestination\tcostI\tcostII\tcostIII\n";
                                      for(i=1;i<=n;i++)
                                      {
                                       p[i].display();
                                      }
                                      do
                                      {
                   cout<<"\n1.TRAIN NUMBER\n2.SEATS\n3.NAME\n4.BOARDING PLACE\n5.DESTINATION PLACE\n6.COST I\n7.COST II\n8.COST III\n9.DISPLAY\n10.EXIT";
                                      cin>>cho;
                                      if(cho<9)
                                      {
                                      cout<<"\nEnter train serial number\t:";
                                      cin>>se;
                                      }
                                      switch (cho)
                                      {
                                                case 1:
                                                {
                                                          cout<<"\nEnter new train number\t:";
                                                          cin>>trainno;
                                                          p[se].tr_no=trainno;
                                                          break;
                                                }
                                                case 2:
                                                {
                                                          cout<<"\nEnter new no. of seats\t:";
                                                          cin>>st;
                                                          p[se].seats=st;
                                                         break;
                                                }
                                                case 3:
                                                {
                                                          cout<<"\nEnter new name\t: ";
                                                          cin>>name;
                                                          strcpy(p[se].tr_name,name);
                                                          break;
                                                }
                                                case 4:
                                                {
                                                          cout<<"\nEnter new boarding place\t:";
                                                          cin>>bo;
                                                          strcpy(p[se].b,bo);
                                                          break;
                                                }
                                                case 5:
                                                {
                                                          cout<<"\nEnter new destination place\t:";
                                                          cin>>dp;
                                                          strcpy(p[se].d,dp);
                                                          break;
                                                }
                                                case 6:
                                                {
                                                          cout<<"\nEnter new cost I";
                                                          cin>>co1;
                                                          p[se].cost1=co1;
                                                          break;
                                                }
                                                case 7:
                                                {
                                                          cout<<"\nEnter new cost II";
                                                          cin>>co2;
                                                          p[se].cost2=co2;
                                                          break;
                                                }
                                                case 8:
                                                {
                                                          cout<<"\nEnter new cost III";
                                                          cin>>co3;
                                                          p[se].cost3=co3;
                                                          break;
                                                }
                                                case 9:
                                                {
                                                           cout<<"\nTrain no\tSeats\tName\tBoarding\tDestination\tcostI\tcostII\tcostIII\n";
                                                          for(i=1;i<=n;i++)
                                                          {
                                                                    p[i].display();
                                                          }

                                                }
                                                }

                                                 }while(cho<10);
                                      break;
                                      }
                                       case 2:
                                      {
                                      cout<<"\n\t\tWELCOME TO SKCET RAILWAYS";
                                       cout<<"\nCURRENT TRAIN STATUS\n";
                                      cout<<"\nTrain no     Seats    Name   Boarding   Destination     costI    costII    costIII\n";
                                      for(i=1;i<=n;i++)
                                      {
                                       p[i].display();
                                      }
                                      do
                                      {
                                       cout<<"\n1.RESERVATION\n2.CANCELATION\n3.STATUS\n4.EXIT";
                                      cin>>choice2;
                                      switch (choice2)
                                      {
                                      case 1:
                                      {
                                      cout<<"\nEnter train name\t:";
                                      cin>>name;
                                      for(i=1;i<=n;i++)
                                      {
                                      if(strcmp(p[i].tr_name,name)==0)
                                      {
                                                cout<<"\nEnter total number of seats \t:";
                                                cin>>seats1;
                                                if(p[i].seats>seats1)
                                                {
                                                pn++;
                                                p[i].seats=p[i].seats-seats1;
                                                for(j=1;j<=seats1;j++)
                                                {
                                                cout<<"\nEnter name for person "<<j<<"\n";
                                                cin>>pname;
                                                cout<<"\nEnter age for person "<<j<<"\n";
                                                cin>>page;
                                                cout<<"\nEnter the class\t:";
                                                cin>>cl;
                                                pas[j]=passenger(pname,page,cl,pn);
                                                pas[j].reserve(i,cl,p,common);
                                                pas[j].calc(common);
                                                }
                                                cout<<"\n --------------------------------------------------------------------------";
                                                cout<<"\n -\t\t\t  |@| SKCET RAILWAYS |@|\t\t-";
                                                cout<<"\n - Train No.\tTrain name\tBoarding place\tDestination\tStatus\tPNR -";
                                                          pas[j].display1(i,p);
                                                          cout<<"\n - Name\tAge\tCost\t\t\t\t\t\t\t- ";
                                                for(j=1;j<=seats1;j++)
                                                {
                                                          pas[j].display2(1);
                                                }
                                                cout<<"\n----------------------------------------------------------------------------";
                                      flag=1;
                                                }//if
                                                else
                                                {
                                                          pn++;
                                                          seats2=seats1-p[i].seats;
                                                          seats3=seats1-seats2;
                                                          p[i].seats=0;
                                                for(j=1;j<=seats3;j++)
                                                {
                                                cout<<"\nEnter name for person "<<j<<"\n";
                                                cin>>pname;
                                                cout<<"\nEnter age for person "<<j<<"\n";
                                                cin>>page;
                                                cout<<"\nEnter the class\t:";
                                                cin>>cl;
                                                pas[j]=passenger(pname,page,cl,pn);
                                                pas[j].reserve(i,cl,p,common);
                                                pas[j].calc(common);
                                                }
cout<<"\n -------------------------------------------------------------------------------";
cout<<"\n -\t\t\t  |@| SKCET RAILWAYS |@|\t\t-";
cout<<"\n - Train No.\tTrain name\tBoarding place\tDestination\tStatus\tPNR -";
pas[j].display1(i,p);
for(j=1;j<=seats3;j++)
{
pas[j].display2(1);
}
cout<<"\n - LAST "<<seats2<<" WAIT LISTED \t\t\t\t\t\t";
cout<<"\n--------------------------------------------------------------------------------";
                                      flag=1;

                                                }
                                                }//1st if
                                                }//for
                               //      }//
                                      if(flag==0)
                                      {
                                                cout<<"\nTRAIN UNAVAILABLE\n";
                                      }
                                      break;
                                      }//case1(reservation)
                                      case 2:
                                      {
                                                cout<<"\nEnter train name\t:";
                                                cin>>name;
                                                for(i=1;i<=n;i++)
                                                {
                                                         if(strcmp(p[i].tr_name,name)==0)
                                                          {
                   cout<<"\nEnter number of seats you wish to cancel\t";
                                                                   cin>>seats;
                                                                   p[i].seats=p[i].seats+seats;
cout<<"\nYOUR TICKET HAS BEEN SUCCESSFULLY CANCELLED\n";
                                                          }
                                                }
                                                break;
                                      }
                                      case 3:
                                      {
                                                cout<<"\nEnter train name\t:";
                                                cin>>name;
                                                          for(i=1;i<=n;i++)
                                                {
                                                          if(strcmp(p[i].tr_name,name)==0)
                                                          {
                                                                   cout<<"\nEnter PNR number\t";
                                                                   cin>>pn;
                                                                   for(j=1;j<=p[i].seats;j++)
                                                                   {
                                                                   if(pas[j].pnr==pn)
                                                                   {
                                                                             if(pas[j].status==1)
                                                                             {
                                                                                      cout<<"\nConfirmed";
                                                                             }
                                                                             else
                                                                             {
                                                                                      cout<<"\nWait List";
                                                                             }
                                                                   }
                                                                   }
                                                          }
                                                }

                                      break;
                                      }
                                      }

                                      }while(choice2<4);
                                      break;
                             }
                             }
                             }while(ch!=3);
                             return 0;
                   }


OUTPUT:

                 <<<***   SKCET RAILWAYS   ***>>>
        WELCOME ADMINISTRATOR
Enter the total number of trains2

Enter the details for train 1

Enter name      :cheran

Enter train no  :1224

Enter boarding place    :cbe

Enter destination place :mad

Enter the number of seats available     :3

Enter cost per head for I class :6

Enter cost per head for II class        :4

Enter cost per head for III class       :2

Enter the details for train 2

Enter name      :bluemountain

Enter train no  :1443

Enter boarding place    :cbe

Enter destination place :bgl

Enter the number of seats available     :3

Enter cost per head for I class :7

Enter cost per head for II class        :4

Enter cost per head for III class       :2

Train no     Seats   Name       Boarding        Destination     costI   costII   costIII
1224             3       cheran               cbe         mad                      6       4       2
1443             3       bluemountain    cbe         bgl                        7       4       2

1.ADMINSTRATOR
2.PASSENGER1

CURRENT TRAIN STATUS

Train no     Seats   Name       Boarding      Destination     costI   costII    costIII
1224                3    cheran               cbe                    mad         6       4       2
1443                3    bluemountain    cbe                      bgl        7       4       2

1.TRAIN NUMBER
2.SEATS
3.NAME
4.BOARDING PLACE
5.DESTINATION PLACE
6.COST I
7.COST II
8.COST III
9.DISPLAY
10.EXIT1

Enter train serial number       :1

Enter new train number  :1551

1.TRAIN NUMBER
2.SEATS
3.NAME
4.BOARDING PLACE
5.DESTINATION PLACE
6.COST I
7.COST II
8.COST III
9.DISPLAY
10.EXIT9

Train no    Seats        Name       Boarding    Destination     costI   costII   costIII
1551                 3       cheran               cbe     mad                      6       4       2
1443                 3       bluemountain    cbe     bgl                        7       4       2

1.TRAIN NUMBER
2.SEATS
3.NAME
4.BOARDING PLACE
5.DESTINATION PLACE
6.COST I
7.COST II
8.COST III
9.DISPLAY
10.EXIT10

1.ADMINSTRATOR
2.PASSENGER2

                WELCOME TO SKCET RAILWAYS
CURRENT TRAIN STATUS

Train no     Seats    Name   Boarding   Destination     costI    costII    costI
II
1551    3       cheran  cbe     mad     6       4       2
1443    3       bluemountain    cbe     bgl     7       4       2

1.RESERVATION
2.CANCELATION
3.STATUS
4.EXIT1

Enter train name        :cheran

Enter total number of seats     :5

Enter name for person 1
sri

Enter age for person 1
18

Enter the class :1

Enter name for person 2
ram

Enter age for person 2
16

Enter the class :1

Enter name for person 3
veera

Enter age for person 3
17

Enter the class :1

 --------------------------------------------------------------------------------------------------

 -                        |@| SKCET RAILWAYS |@|                                                             -
 - Train No.    Train name      Boarding place  Destination     Status           PNR    -
 - 1551             cheran            cbe                      mad                                    2546    -    
 - sri                 18                6                                             CONFIRMED               -     
 - ram               16                6                                             CONFIRMED               -
 - veera             17                6                                             CONFIRMED              -
 - LAST 2 WAIT LISTED
---------------------------------------------------------------------------------------------------


1.RESERVATION
2.CANCELATION
3.STATUS
4.EXIT2

Enter train name        :cheran

Enter number of seats you wish to cancel        1

YOUR TICKET HAS BEEN SUCCESSFULLY CANCELLED


1.RESERVATION
2.CANCELATION
3.STATUS
4.EXIT3

Enter train  name             :cheran

Enter PNR  number          :2546

Confirmed

1.RESERVATION
2.CANCELATION
3.STATUS
4.EXIT4

1.ADMINSTRATOR
2.PASSENGER3

No comments:

Post a Comment