Bus Reservation System

#include<conio.h>
#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
#include<dos.h>
#include<graphics.h>
#include<stdlib.h>
//THIS CLASS CONTAIN ALL THE FUNCTIONS RELATED TO TICKET

class TRAVEL
 {
     public:
       void INFORMATION(void);
       void RESERVATION(void);
       int RESERVED(int,int,int,int,int);
       int AVAIL(int,int,int,int);
       void DELETION(void);
       void LIST_OF_PASS(void);
       void PASS_INFO(void);
       void MAINMENU(void);
    private:
       int busno,seatno;
       char name[26],sex;
       int age,fair;
       int dd,mm,yy;
    };
    char *place[3]={"jaipur","agra","ajmer"};
    int price[3]={100,220,110};
//THIS FUNCTION DISPLAY THE PASSENGER INFORMATION


void TRAVEL::PASS_INFO(void)
  {
     clrscr();
     int bno=0,found=0,sno,d,m,y;
     cout<<"\n Bus 1:bikaner to jaipur.       <fare Rs.100>";
     cout<<"\n Bus 2:bikaner to agra.         <fare Rs.220>";
     cout<<"\n Bus 3:bikaner to ajmer.        <fare Rs.110>";
     do
       {
     cout<<"\n\n enter the busno.(1/2/3)";
     cin>>bno;
       }while(bno<1||bno>3);
     cout<<"\n\n enter the date of the reserved ticket:";
     cin>>d;
     cout<<"\n\n enter the month:";
     cin>>m;
     cout<<"\n\n enter the year:";
     cin>>y;
     cout<<"\nenter the seat no.:";
     cin>>sno;
     if(sno>60||sno<1||!RESERVED(bno,d,m,y,sno))
       {
     cout<<"\n\n\nsorry!\7seat not reserved";
     getch();
     return;
       }
     fstream file;
     file.open("BUS.DAT",ios::in);
     while(file.read((char *)this,sizeof(TRAVEL)))
       {
     if((dd==d&&mm==m&&yy==y)&&bno==busno&&sno==seatno)
       {
         found=1;
         clrscr();
         gotoxy(5,5);



         cout<<"**********************************************************************";
         gotoxy(28,7);
         cout<<"cpptute.bus trevel agency";
         gotoxy(10,9);
         cout<<"BUS NO."<<bno<<"\t\t\tDATE:"<<d<<"/"<<m<<"/"<<y;
         gotoxy(10,10);
         cout<<"SEAT NO.:"<<sno;
         gotoxy(35,12);
         cout<<"FROM:BIKANER"<<"\tTo:"<<place[bno-1];
         gotoxy(10,15);
         cout<<"Passenger Name:"<<name;
         gotoxy(10,16);
         cout<<"Passenger Age:  "<<age<<"\t\tsex:"<<sex;
         gotoxy(10,18);
         cout<<"Total Fair   :" <<price[bno-1];
         gotoxy(5,20);
         cout<<"************************************************************************";
         gotoxy(1,25);
         cout<<"press any key to continue...";
         getch();
         break;
       }
       }
     file.close();
     if(!found)
       {
     cout<<"\n\n7passenger record not found";
     getch();
       }
  }
//This function gives the list of all the passenger
void TRAVEL::LIST_OF_PASS(void)
  {
     clrscr();
     int bno=0,found=0,row=8;
     char ch;
     cout<<"\n Bus 1:Bikaner to jaipur. <fare Rs.100>";
     cout<<"\n Bus 2:Bikaner to agra.   <fare Rs.220>";
     cout<<"\n Bus 3:Bikaner to ajmer.  <fare Rs.110>";
     do
       {
     cout<<"\n\nenter the bus no.(1/2/3)";
     cin>>bno;
       }while(bno<1||bno>3);
     do
       {
     cout<<"\n Do you want date wise report(y/n)";
     cin>>ch;
       }while(toupper(ch)!='N'&& toupper(ch)!='Y');
     int d=0,m=0,y=0;
     if(toupper(ch)=='Y')
       {
     cout<<"\n\n Enter  date:";
     cin>>d;
     cout<<"\n\n Enter month:";
     cin>>m;
     cout<<"\n\n Enter year:";
     cin>>y;
       }
     clrscr();
     gotoxy(25,1);
     cout<<"LIST OF THE PASSENGERS ";
     gotoxy(24,2);
     cout<<"\n***********************************************************************"<<endl;
     gotoxy(1,3);
     cout<<" BUS NO.:"<<bno<<"\t\t\t\t\tfrom: BIKANER  TO:"<<place[bno-1];
     gotoxy(2,5);
     cout<<"SEAT NO.   PASSENGER NAME               SEX    AGE    DATE ";
     gotoxy(2,6);
     cout<<"**************************************************************************"<<endl;
     fstream file;
     file.open("BUS.DAT",ios::in);
     while(file.read((char*)this,sizeof(TRAVEL)))
       {
     if(busno==bno)
     {
      if((toupper(ch)=='N')||((toupper(ch)=='Y')&&(dd==d&&mm==m&&yy==y)))
      {
       found=1;
       gotoxy(5,row);
       cout<<seatno;
       gotoxy(14,row);
       cout<<name;
       gotoxy(43,row);
       cout<<sex;
       gotoxy(50,row);
       cout<<age;
       gotoxy(61,row);
       cout<<dd<<"/"<<mm<<"/"<<yy;
       row++;
       if(row==25)
         {
           getch();
           for(int i=8;i<=24;i++)
           {
         gotoxy(1,i);
         clreol();
           }
         row=8;
      }
     }
       }
     }
     file.close();
     if(!found)
       {
     cout<<"\n\n\n\n\n\7No reservation for the bus no. "<<bno;
     getch();
     return;
       }
     cout<<"\n\nPress any key to continue..............";
     getch();
  }

int TRAVEL::AVAIL(int bno,int d,int m,int y)
  {
     fstream file;
     file.open("BUS.DAT",ios::in);
     int avail=0,count=0;
     while(file.read((char*)this,sizeof(TRAVEL)))
       {
     if(dd==d&&mm==m&&yy==y&&bno==busno)
     count++;
       }
     if(count<60)
     avail=1;
     file.close();
     return avail;
  }

int TRAVEL::RESERVED(int bno,int d,int m,int y,int sno)
  {
     fstream file;
     file.open("BUS.DAT",ios::in);
     int reserved=0;
     while(file.read((char*)this,sizeof(TRAVEL)))
       {
     if(dd==d&&mm==m&&yy==y&&bno==busno&&sno==seatno)
       {
         reserved=1;
         break;
       }
       }
     file.close();
     return reserved;
  }


       /* FUNCTION TO RESERVE TICKET */

void TRAVEL::RESERVATION(void)
  {

     clrscr();
     int bno,sno,pfair,page;
     char ch,pname[26],psex;
     cout<<"\n Bus 1:Bikaner to jaipur. <fare Rs.100>";
     cout<<"\n Bus 2:Bikaner to agra.   <fare Rs.220>";
     cout<<"\n Bus 3:Bikaner to ajmer.  <fare Rs.110>";
     do
       {
     cout<<"\n\nenter the bus no.(1/2/3)";
     cin>>bno;
       }while(bno<1||bno>3);
     int d,m,y;
     cout<<"\n\n Enter the date for reservation :";
     cin>>d;
     cout<<"\n\n Enter month:";
     cin>>m;
     cout<<"\n\n Enter year:";
     cin>>y;
     if(!AVAIL(bno,d,m,y))
       {
     cout<<"\n\n\nsorry!\7seat not available";
     getch();
     return;
       }
     cout<<"\nEnter the seat no.:";
     cin>>sno;
     if(sno>60||sno<1||RESERVED(bno,d,m,y,sno))
       {
     cout<<"\n\n\nsorry!\7seat already reserved";
     getch();
     return;
       }
     cout<<"\n Enter name of passenger:";
     gets(pname);
     do
       {
     cout<<"Enter sex of passenger(M/F):";
     cin>>psex;
       }while(toupper(psex)!='M'&&toupper(psex)!='F');
     cout<<"enter age:";
     cin>>page;
     if(page<=5)
       {
     cout<<"\7\n No ticket is required upto the age of 5";
     getch();
     return;
    }
     clrscr();
     gotoxy(5,5);
     cout<<"**********************************************************************"<<endl;
     gotoxy(28,7);
     cout<<"cpptute.bus travel agency";
     gotoxy(10,9);
     cout<<"BUS NO."<<bno<<"\t\t\tDATE:"<<d<<"/"<<m<<"/"<<y;
     gotoxy(10,10);
     cout<<"SEAT NO.:"<<sno;
     gotoxy(35,12);
     cout<<"FROM:BIKANER"<<"\tTo:"<<place[bno-1];
     gotoxy(10,15);
     cout<<"Passenger Name:"<<pname;
     gotoxy(10,16);
     cout<<"Passenger Age:  "<<page<<"\t\tsex:"<<psex;
     gotoxy(10,18);
     cout<<"Total Fair   :" <<price[bno-1];
     gotoxy(5,20);
     cout<<"**********************************************************************";
     cout<<"\n\n\n";
     do
       {
     cout<<"Do you want to save ticket(y/n)";
     cin>>ch;
       }while(toupper(ch)!='N'&& toupper(ch)!='Y');
     if(toupper(ch)=='N')
     return;
     fstream file;
     file.open("BUS.DAT",ios::app);
     busno=bno;
     seatno=sno;
     strcpy(name,pname);
     sex=psex;
     age=page;
     fair=pfair;
     dd=d;
     mm=m;
     yy=y;
     file.write((char*)this,sizeof(TRAVEL));
     file.close();
  }


      /*FUNCTION TO DELETE RECORD OF THE PASSENGER */

void TRAVEL::DELETION(void)
  {
     clrscr();
     int bno=0,found=0,sno,d,m,y;
     char ch;
     cout<<"\n Bus 1:bikaner to jaipur.       <fare Rs.100>";
     cout<<"\n Bus 2:bikaner to agra.         <fare Rs.220>";
     cout<<"\n Bus 3:bikaner to ajmer.        <fare Rs.110>";
     do
       {
     cout<<"\n\n enter the busno.(1/2/3)";
     cin>>bno;
       }while(bno<1||bno>3);
     cout<<"\n\n enter the date of the reserved ticket:";
     cin>>d;
     cout<<"\n\n enter the month:";
     cin>>m;
     cout<<"\n\n enter the year:";
     cin>>y;
     cout<<"\nenter the seat no.:";
     cin>>sno;
     if(sno>60||sno<1||!RESERVED(bno,d,m,y,sno))
       {
     cout<<"\n\n\nsorry!\7seat not reserved";
     getch();
     return;
       }
     fstream file,temp;
     file.open("BUS.DAT",ios::in);
     temp.open("TEMP.DAT",ios::out);
     while(file.read((char*)this,sizeof(TRAVEL)))
       {
     if(dd==d&&mm==m&&yy==y&&bno==busno&&sno==seatno)
     {
       found=1;
       clrscr();
       gotoxy(5,5);
       cout<<"************************************************************************";
       gotoxy(28,7);
       cout<<"cpptute.bus travel agency";
       gotoxy(10,9);
       cout<<"BUS NO."<<bno<<"\t\t\tDATE:"<<d<<"/"<<m<<"/"<<y;
       gotoxy(10,10);
       cout<<"SEAT NO.:"<<sno;
       gotoxy(35,12);
       cout<<"FROM:BIKANER"<<"\tTo:"<<place[bno-1];
       gotoxy(10,15);
       cout<<"Passenger Name:"<<name;
       gotoxy(10,16);
       cout<<"Passenger Age:  "<<age<<"\t\tsex:"<<sex;
       gotoxy(10,18);
       cout<<"Total Fair   :" <<price[bno-1];
       gotoxy(5,20);
       cout<<"*********************************************************************";
       do
         {
           gotoxy(1,25);
           clreol();
           cout<<"Do you want to delete(y/n)";
           cin>>ch;
         }while(toupper(ch)!='N'&& toupper(ch)!='Y');
       if(toupper(ch)=='N')
       temp.write((char *)this,sizeof(TRAVEL));
       }
     else
     temp.write((char *)this,sizeof(TRAVEL));
     }
     file.close();
     temp.close();
     if(!found)
       {
     cout<<"\n\n\7Passenger record not found";
     getch();
     return;
       }
     if(toupper(ch)=='N')
     return;
     file.open("BUS.DAT",ios::out);
     temp.open("TEMP.DAT",ios::in);
     while(temp.write((char*)this,sizeof(TRAVEL)));
     file.write((char*)this,sizeof(TRAVEL));
     file.close();
     temp.close();
  }


void TRAVEL::INFORMATION(void)
  {
     clrscr();
     gotoxy(20,8);
     cout<<"INTRODUCTION OF cpptute.bus travel agency";
     gotoxy(4,10);
     cout<<"In this agency there are three buses whose routes are:";
     gotoxy(15,12);
     cout<<"BUS 1.BIKANER TO JAIPUR.    <FARE RS 100>";
     gotoxy(15,13);
     cout<<"BUS 2.BIKANER TO AGRA.      <FARE RS 220>";
     gotoxy(15,14);
     cout<<"BUS 3.BIKANER TO AJMER.     <FARE RS 110>";
     gotoxy(4,16);
     cout<<"you can reserve ticket of any date and later on cancel the same also.";
     gotoxy(28,23);
     cout<<"press any key to continue.......";
     getch();
  }
/*   MAIN FUNCTION WHICH DISPLAY MAIN MENU & CALL ALL OTHER FUNCTIONS */

void MAINMENU(void)
  {
     TRAVEL travel;
     char ch;
     while(1)
       {
     for (int i=0; i<8;i++)
       {
         for (int j=0; j<20; j++)
         textcolor(i+1);
         textbackground(i);
       }
     clrscr();
     gotoxy(15,4);
     cout<<"******************************************************";
     gotoxy(26,5);
     cout<<"c";
     delay(100);
     cout<<"p";
     delay(100);
     cout<<"p";
     delay(100);
     cout<<"t";
     delay(100);
     cout<<"u";
     delay(100);
     cout<<"t";
     delay(100);
     cout<<"t";
     delay(100);
     cout<<"R";
     delay(100);
     cout<<"A";
     delay(100);
     cout<<"V";
     delay(100);
     cout<<"E";
     delay(100);
     cout<<"L";
     delay(100);
     cout<<" A";
     delay(100);
     cout<<"G";
     delay(100);
     cout<<"E";
     delay(100);
     cout<<"N";
     delay(100);
     cout<<"C";
     delay(100);
     cout<<"Y";
     cout<<"(";
     delay(100);
     cout<<"P";
     delay(100);
     cout<<"V";
     delay(100);
     cout<<"T";
     delay(100);
     cout<<".";
     delay(100);
     cout<<"L";
     delay(100);
     cout<<"T";
     delay(100);
     cout<<"D";
     delay(100);
     cout<<")"<<endl;
     delay(100);
     gotoxy(15,6);
     cout<<"******************************************************";
     gotoxy(22,9);
     cout<<"*    PROP.WRITER   *";
     gotoxy(48,10);
     cout<<"cpptute.blogspot.com";
     gotoxy(29,13);
     cout<<"1::INTRODUCTION";
     gotoxy(29,14);
     cout<<"2::RESERVATION";
     gotoxy(29,15);
     cout<<"3::DELETE RECORD";
     gotoxy(29,16);
     cout<<"4::PASSENGER LIST";
     gotoxy(29,17);
     cout<<"5::PASSENGER INFORMATION";
     gotoxy(29,18);
     cout<<"6::QUIT";
     gotoxy(29,20);
     cout<<"Enter your choice::";
     ch=getche();
     if(ch==27||ch=='6')
         {
           clrscr();
           int gdriver = DETECT, gmode;
           int midx, midy, ht;
           initgraph(&gdriver, &gmode, "../bgi");
           midx = getmaxx() / 2;
           midy = getmaxy() / 2;
           setcolor(1);
           settextstyle(TRIPLEX_FONT,0,3);
           settextjustify(CENTER_TEXT, CENTER_TEXT);
           outtextxy(midx,midy,"THANK YOU PLEASE VISIT US AGAIN");
           break;
         }
     else
     if(ch=='1')
     travel.INFORMATION();
     else
     if(ch=='2')
     travel.RESERVATION();
     else
     if(ch=='3')
     travel.DELETION();
     else
     if(ch=='4')
     travel.LIST_OF_PASS();
     else
     if(ch=='5')
     travel.PASS_INFO();
       }
  }

       //MAIN function to call all the functions
void main()
  {
     int gdriver = DETECT, gmode;
     initgraph(&gdriver, &gmode, "../bgi");
     setcolor(1);
     setbkcolor(0);
     settextstyle(TRIPLEX_FONT,0,1);
     outtextxy(130, 230,"WELCOME TO cpptute.bus travel agency" );
     rectangle(100,150,500,300);
     setfillstyle(3, getmaxcolor());
     pieslice(150, 300, 0, 360, 23);
     setfillstyle(3, getmaxcolor());
     pieslice(450, 300, 0, 360, 23);
     line(100,220,500,220);
     line(100,170,500,170);
     line(170,170,170,220);
     line(240,170,240,220);
     line(310,170,310,220);
     line(380,170,380,220);
     line(460,170,460,220);
     line(500,150,550,300);
     line(500,300,550,300);
     getch();
     closegraph();
     MAINMENU();
     getch();
  }