Bus Reservation system using c++(New)


#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<iomanip.h>
#include<dos.h>
#include<fstream.h>
#include<ctype.h>
#include<string.h>
#include<graphics.h>



void startup();




class danphetravel
{
 private:
 char name[50],from[30],add[80],to[30],month[10],flag;
 float price;
 int seatno,day;
 double cellno;
 int fare;
 public:
 int i;
 void reserve();
 void displayreservations();
 void showtransportrec();
 void deltransportrec();
 void searchtransportrec();
 void transfertransportdata();
 void edittransportdata();
 void transfertransportdata1();
 void userscreen();
void getonce()
{    clrscr();
cout<<"\n\n\n\Enter Total Seat of the Bus\n";

cin>>i;
cout<<"\n\n\n\nSet Bus fare\n\n\n";
cin>>fare;
}

void decrease()
{
i=i-1;
}
void increase()
{
i=i+1;
}

void recordfile();
}bookseat;


int main()
{
     clrscr();
     startup();
fstream fcheck;

bookseat.getonce();
fcheck.open("check.txt",ios::out);
fcheck.write((char*)&bookseat,sizeof(bookseat));
fcheck.close();
     clrscr();
     textbackground(YELLOW);
textcolor(RED);
     int select;
     do
     {
  cout<<"\n\n";
  cout<<"\t\t\t--->>>D A N P H E___D E L U X E<<<--- \n\n";
  cout<<"\t\t\t W E L C O M E--T O--M A I N--M E N U   \n\n\n";
  cout<<"\t\t\t1. Make a Reservation\n";
  cout<<"\t\t\t2. View Reservations\n";
  cout<<"\t\t\t3. Edit a Reservation\n";
  cout<<"\t\t\t4. Search for a Reservation\n";
  cout<<"\t\t\t5. Delete a Reservation\n";
  cout<<"\t\t\t6. Exit\n\n";
  cout<<"\t\t\tSelect an option: ";
  cin>>select;
  switch(select)
  {
         case 1:



     bookseat.recordfile();



       break;
         case 2:
       bookseat.showtransportrec();

       break;
         case 3:
       bookseat.edittransportdata();
       break;
         case 4:
       bookseat.searchtransportrec();
       break;
         case 5:
       bookseat.deltransportrec();
       break;

         default:
          cout<<"Invalid Input.Try again!!";
          break;
  }
     }
     while(select!=6);
     return 0;
}




void danphetravel::reserve()
{
clrscr();


flag='N';
 while(flag!='Y')
 {
 clrscr();
 userscreen();
clrscr();
   textbackground(RED);
textcolor(BLUE);
   gotoxy(25,5);cout<<"PLEASE FILL IN THE DETAILS PROPERLY...";
   gotoxy(25,5);cout<<"DANPHE DELUXE TICKET RESERVATION FORM";
   gotoxy(5,8);cout<<"Name: ";
   gotoxy(5,10);cout<<"Address: ";
   gotoxy(5,12);cout<<"From: ";
   gotoxy(30,12);cout<<"To: ";
   gotoxy(5,14);cout<<"No of Ticket:";
   gotoxy(5,16);cout<<"Contact No:";
   gotoxy(5,18);cout<<"Month:";
   gotoxy(5,20);cout<<"Day:";
   gotoxy(10,22);cout<<"Is the information correct(y/n)?? ";
   gotoxy(10,8);gets(name);
   gotoxy(13,10);gets(add);
   gotoxy(19,12);gets(from);
   gotoxy(40,12);gets(to);
   gotoxy(20,14);cin>>seatno;
   gotoxy(18,16);cin>>cellno;
   gotoxy(18,18);gets(month);
   gotoxy(18,20);cin>>day;
   gotoxy(45,22);cin>>flag;
 flag=toupper(flag);
}
bookseat.decrease();
fstream f2;
 f2.open("check.txt", ios::out );
       f2.write ((char*)&bookseat,sizeof (bookseat));
f2.close();

displayreservations();
}


void danphetravel::userscreen()
{
clrscr();
textbackground(GREEN);
textcolor(RED);

    for(int k=13;k<17;k++)
    {  clrscr();
  gotoxy(k,10);cout<< ("Û       Û  ÛÛÛÛÛ Û      ÛÛÛÛÛÛ  ÛÛÛÛÛÛ  Û   Û ÛÛÛÛÛÛ     \n\n    ");
  gotoxy(k,11);cout <<("Û       Û  Û     Û      Û       Û    Û  ÛÛ ÛÛ Û         ");
  gotoxy(k,12);cout <<("Û   Û   Û  ÛÛÛÛ  Û      Û       Û    Û  Û Û Û ÛÛÛÛ    ");
  gotoxy(k,13);cout <<("Û   Û   Û  Û     Û      Û       Û    Û  Û   Û Û       ");
  gotoxy(k,14);cout <<("ÛÛÛÛÛÛÛÛÛ  ÛÛÛÛÛ ÛÛÛÛÛÛ ÛÛÛÛÛÛ  ÛÛÛÛÛÛ  Û   Û ÛÛÛÛÛÛ    ");
}
gotoxy(25,25);cout<<"press any key to start reservation....";
getch();
}

void danphetravel::displayreservations()
{


 clrscr();

 clrscr();
 textbackground(YELLOW);
textcolor(RED);
 gotoxy(25,5);cout<<"WELCOME TO DANPHE DELUXE TICKET RESERVATION  ";
 gotoxy(24,6);cout<<"----------------------------------------------";
 gotoxy(15,8);cout<<"Name:"<<strupr(name);
 gotoxy(15,10);cout<<"Address:"<<strupr(add);
 gotoxy(15,12);cout<<"From:    "<<from
     <<"   To:"<<to;
 gotoxy(15,14);cout<<"No of Ticket:"<<seatno;
 gotoxy(15,16);cout<<"Contact No:"<<cellno;
 gotoxy(15,18);cout<<"Month:"<<month<<"  Day:"<<day;

 gotoxy(15,20);cout<<"Your Reservations have been done Please pay the Amount!!!";
 gotoxy(25,22);cout<<"Please pay Amount: Rs."<<fare*seatno<<"  To Complete Reservation";
 getch();
}

void danphetravel::showtransportrec()
{
fstream file1;
file1.open("transport.txt",ios::in);
 while(file1.read((char*)&bookseat,sizeof (bookseat)))
 bookseat.displayreservations();;
file1.close();
}


void danphetravel::deltransportrec()
{
clrscr();
textbackground(YELLOW);
textcolor(RED);
  char delname[20];
  gotoxy(20,5);cout<<"Enter name to delete record for...";
  gotoxy(30,7);gets(delname);
  strupr(delname);
    fstream  file2,file3;
    int dele=0;
    file2.open("transport.txt", ios::in);
    file3.open("temp3.txt", ios::out );
       while(file2.read ((char*)&bookseat,sizeof (bookseat)))
       {
       if ((strcmp(name,delname))!=0)
       file3.write((char*)&bookseat,sizeof (bookseat));
       else
       dele++;
       }
       if(dele!=0)
       {cout<<endl<<"                    ...Deleted...";


bookseat.increase();
fstream fcheck;
fcheck.open("check.txt", ios::out);

fcheck.write((char*)&bookseat,sizeof(bookseat));
fcheck.close();
}









       else
       cout<<endl<<"                  Record not found..";
       getch();
       file2.close();
       file3.close();
       transfertransportdata();
}

void danphetravel::transfertransportdata()
{
fstream oldfile1,newfile1;
oldfile1.open("temp3.txt", ios::in);
newfile1.open("transport.txt", ios::out);
     while(oldfile1.read((char*)&bookseat,sizeof(bookseat)))
     newfile1.write((char*)&bookseat,sizeof (bookseat));
oldfile1.close();
newfile1.close();
}



void danphetravel::searchtransportrec()
{
clrscr();
textbackground(YELLOW);
textcolor(GREEN);
 char sename[20];
 gotoxy(20,5);cout<<"Enter Name to search for..";
 gotoxy(25,7);gets(sename);
 strupr(sename);
    fstream file4;
    file4.open("transport.txt", ios::in);
    int serch=0;
       while(file4.read((char*)&bookseat,sizeof (bookseat)))
       {
 if(strcmp(name,sename)==0)
 {
 serch++;
 bookseat.displayreservations();;
 }
       }
       if(serch==0)
       cout<<"                       No Record Exists";
       file4.close();
       getch();
}

void danphetravel::edittransportdata()
{
clrscr();
textbackground(BLUE);
textcolor(RED);
  char edname[30];
  int ede1=0;
  gotoxy(20,5);cout<<"Enter Name to Edit Record for...";
  gotoxy(25,7);gets(edname);
  strupr(edname);
  fstream file5,file6;
  file5.open("transport.txt", ios::in) ;
  file6.open("temp2.txt", ios::out ) ;
   while(file5.read((char*)&bookseat,sizeof(bookseat)))
  {
   if (strcmp (edname,name)==0)
   {
    reserve();
    ede1++;
   }
   file6.write((char*)&bookseat,sizeof (bookseat));
  }
if(ede1==0)
{
gotoxy(25,17);cout<<"RECORD DOESNT EXIST!!!!";
}
getch();
file5.close();
file6.close();

transfertransportdata1();
}

void danphetravel::transfertransportdata1()
{
fstream oldfile3,newfile3;
oldfile3.open("temp2.txt", ios::in);
newfile3.open("transport.txt",ios::out);
  while(oldfile3.read((char*)&bookseat,sizeof(bookseat)))
  newfile3.write((char*)&bookseat,sizeof (bookseat));
oldfile3.close();
newfile3.close();
}


void danphetravel::recordfile()
{
       fstream file, f1,f2;
       file.open("transport.txt",ios::out |ios::app);

 f1.open("check.txt", ios::in );
       while(f1.read ((char*)&bookseat,sizeof (bookseat)))

{
if(bookseat.i!=0)

{
       bookseat.reserve();
       file.write((char*)&bookseat,sizeof (bookseat));
       file.close();

}
f1.close();
}
 }






void startup()
{
clrscr();
textbackground(YELLOW);
textcolor(RED);
for(int j=0;j<10;j++)
{
clrscr();
gotoxy(j,6); cputs("        ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ");
gotoxy(j,7); cputs("            ÜÜÜÜÜÜÜ ÜÜÜÜÜÜ ÜÜÜÜÜÜ");
gotoxy(j,8); cputs("               Û    Û    Û Û    Û");
gotoxy(j,9); cputs("               Û    ÛÜÜÜÛ  ÛÜÜÜÜÛ");
gotoxy(j,10);cputs("               Û    Û Û    Û    Û");
gotoxy(j,11);cputs("               Û    Û  ÛÛ  Û    Û");

gotoxy(51-j,6); cputs("ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ \n\r");
gotoxy(51-j,7); cputs(" Ü    Ü ÜÜÜÜÜÜ Ü   \n\r");
gotoxy(51-j,8); cputs(" Û    Û Û      Û    \n\r");
gotoxy(51-j,9); cputs(" Û    Û ÛÜÜÜ   Û    \n\r");
gotoxy(51-j,10);cputs("  Û  Û  Û      Û    \n\r");
gotoxy(51-j,11);cputs("   ÛÛ   ÛÛÛÛÛÛ ÛÛÛÛ \n\r\n\n");

gotoxy(j,12);cputs("                          Ü    Ü ÜÜÜÜÜÜ ");
gotoxy(j,13);cputs("                          ÛÛ   Û Û ");
gotoxy(j,14);cputs("                          Û Û  Û ÛÛÛÛ  ");
gotoxy(j,15);cputs("                          Û  Û Û Û ");
gotoxy(j,16);cputs("                          Û   ÛÛ ÛÛÛÛÛÛÛ   ");
gotoxy(j,17);cputs("                     ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ\n\n");

gotoxy(58-j,12);cputs(" ÜÜÜÜÜÜ  ÜÜÜÜÜÜ Ü   \n\r");
gotoxy(58-j,13);cputs(" Û    Û  Û    Û Û      \n\r");
gotoxy(58-j,14);cputs(" ÛÛÛÛÛÛ  ÛÜÜÜÜÛ Û      \n\r");
gotoxy(58-j,15);cputs(" Û       Û    Û Û      \n\r");
gotoxy(58-j,16);cputs(" Û       Û    Û ÛÛÛÛÛÛÛÛÛ   \n\r");
gotoxy(58-j,17);cputs("ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ \n\r");


}


gotoxy(25,25);
cout<<"press any key to continue...";
getch();
}

No comments