Railway Reservation System
Railway Reservation System
RAILWAY RESERVATION
SYSTEM
CLASS XII
SESSION 2018-19
Contents
1. Certificate
2. Acknowledgement
3. Header Files Used
4. Source Code
5. Output Screenshots of
Major Features.
/************************************************************************
//************************************************************************
//************************************************************************
#include<ctype.h>
#include<conio.h>
#include<fstream.h>
#include<string.h>
#include<process.h>
#include<stdio.h>
#include<dos.h>
//************************************************************************
//************************************************************************
struct railway
char name[20],sex,from[20],rstatus[2],nat[10];
int passno,age,des;
};
//************************************************************************
//CLASS TO CONTROL ALL THE FUNCTIONS RELATE TO RAILWAY
RESERVATION.
//************************************************************************
class train
private:
railway r;
void getdata(int);
void add();
void list();
void pinfo();
void cancel();
void mod();
char select();
public:
void srs1();
void srs();
};
//************************************************************************
//FUNCTION NAME:SRS
//************************************************************************
void train::srs1()
do
clrscr();
char choice;
gotoxy(30,2);
cout<<endl;
gotoxy(30,7);
gotoxy(30,9);
gotoxy(30,11);
gotoxy(30,13);
gotoxy(30,15);
gotoxy(30,17);
gotoxy(34,22);
cout<<"ENTER CHOICE:";
choice=getch();
choice=toupper(choice);
switch(choice)
case '5':cancel();break;
case '6':exit(1);
default:cout<<"\a";
}while(1);
//************************************************************************
//************************************************************************
char train::select()
char choice;
do
{
clrscr();
gotoxy(25,5);
cout<<"SELECT A ";
gotoxy(23,6);
gotoxy(27,9);
cout<<"1-SHATABADI\n";
gotoxy(27,10);
cout<<"2-KOLKATA - MAIL\n";
gotoxy(27,11);
cout<<"3-SUPERFAST EXPRESS\n";
gotoxy(27,12);
cout<<"4-RAWALPINDI EXPRESS\n";
gotoxy(27,13);
cout<<"5-RAJDHANI EXPRESS\n";
gotoxy(27,15);
gotoxy(27,16);
cout<<"Q-QUIT TO SYSTEM\n";
gotoxy(30,20);
cout<<"ENTER CHOICE:";
choice=getch();
choice=toupper(choice);
switch(choice)
case '1':return(choice);
case '2':return(choice);
case '3':return(choice);
case '5':return(choice);
case 'R':srs1();
case 'Q':exit(1);
default:cout<<"\a" ;select();
}while(1);
//************************************************************************
//FUNCTION NAME:GETDATA
//************************************************************************
void train::getdata(int p)
char ch;
cout<<"\n 1.DELHI-JAMMU-DELHI";
cout<<"\n 2.DELHI-KANYAKUMARI-DELHI";
cout<<"\n 3.DELHI-BOMBAY-DELHI";
cout<<"\n 4.DELHI-KOLKATA-DELHI";
cin>>r.des;
clrscr();
r.passno=p;
gotoxy(20,7);
cout<<"PASSENGER NO.:";
cout<<r.passno;
gotoxy(20,9);
gets(r.name);
gotoxy(20,10);
cin>>r.sex;
while(1)
gotoxy(34,12);
cout<<" ";
if(r.sex=='m'||r.sex=='M'||r.sex=='f'||r.sex=='F')
break;
gotoxy(34,12);
cout<<"ENTER M or F"<<endl;
getch();
gotoxy(34,12);
cout<<" ";
gotoxy(20,10);
cout<<" ";
gotoxy(20,10);
cin>>r.sex;
gotoxy(20,11);
cin>>r.age;
while(1)
gotoxy(34,12);
cout<<" ";
break;
gotoxy(34,12);
getch();
gotoxy(34,12);
cout<<" ";
gotoxy(20,11);
cout<<" ";
gotoxy(20,11);
cin>>r.age;
}
gotoxy(20,12);
gets(r.nat);
gotoxy(20,13);
cout<<"DELHI\n";
gotoxy(20,14);
switch(r.des)
case 4:cout<<"KOLKATA\n";break;
gotoxy(20,16);
cout<<r.passno;
//************************************************************************
void train::add()
train temp;
int t;
fstream trains;
char c,filename[8],choice1,choice2;
do
t=0;
c=select();
switch(c)
case '2':strcpy(filename,"BRIT.DAT");break;
case '3':strcpy(filename,"GULF.DAT");break;
case '4':strcpy(filename,"UNIT.DAT");break;
trains.open(filename,ios::in|ios::binary|ios::app);
while(trains.read((char*)&temp,sizeof(railway)))
t++;
trains.close();
do
{
if(t<5)
strcpy(r.rstatus,"C");
else strcpy(r.rstatus,"W");
if(t<8)
t++;
clrscr();
gotoxy(25,3);
gotoxy(23,4);
cout<<"IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII";
gotoxy(20,6);
switch(c)
getdata(t);
gotoxy(20,16);
cout<<"STATUS :";
if(t<5)
cout<<"\aCONFIRMED";
getch();
trains.open(filename,ios::out|ios::binary|ios::app);
trains.write((char*)&r,sizeof(railway));
trains.close();
else
clrscr();
gotoxy(22,20);
getch();
gotoxy(12,25);
do
choice1=getch() ;
choice1=toupper(choice1) ;
} while((choice1!='Y')&&(choice1!='N')) ;
} while(choice1=='Y') ;
gotoxy(12,25);
cout<<"DO YOU WISH TO MAKE ANY MORE RESERVATION ON
ANY TRAIN(Y/N)";
do
choice2=getch();
choice2=toupper(choice2);
} while((choice2!='Y')&&(choice2!='N'));
} while(choice2=='Y');
//***************************************************************************
//***************************************************************************
void train::pinfo()
fstream trains;
int p,k=0;
char c,filename[8];
c=select();
switch(c)
case '2':strcpy(filename,"BRIT.DAT");break;
case '3':strcpy(filename,"GULF.DAT");break;
case '4':strcpy(filename,"UNIT.DAT");break;
clrscr();
gotoxy(10,3);
cin>>p;
trains.open(filename,ios::in|ios::binary|ios::app);
while(trains.read((char *)&r,sizeof(railway)))
k++;
trains.close();
if(p>k)
clrscr();
gotoxy(25,25);
getch();
else
trains.open(filename,ios::in|ios::binary|ios::app);
while(trains.read((char *)&r,sizeof(railway)))
{
if(r.passno==p)
clrscr();
gotoxy(27,3);
cout<<"PASSENGER INFORMATION";
gotoxy(23,6);
switch(c)
gotoxy(23,7);
cout<<r.passno;
gotoxy(23,9);
cout<<r.name;
gotoxy(23,10);
cout<<r.sex;
gotoxy(23,11);
cout<<r.age;
gotoxy(23,12);
cout<<"NATIONALITY :";
cout<<r.nat;
gotoxy(23,13);
cout<<"DELHI";
gotoxy(23,14);
cout<<"DESTINATION :";
switch(r.des)
case 4:cout<<"KOLKATA\n";break;
gotoxy(23,16);
cout<<r.passno;
gotoxy(23,17);
cout<<"STATUS :";
if(strcmp(r.rstatus,"W")==0)
cout<<"WAITING LIST";
else cout<<"CONFIRMED";
gotoxy(5,25);
getch();
} trains.close();
//***************************************************************************
//***************************************************************************
void train::list()
fstream trains;
char c,filename[8];
c=select();
switch(c)
clrscr();
gotoxy(29,3);
cout<<"PASSENGER LIST";
gotoxy(27,4);
cout<<"IIIIIIIIIIIIIIIIIIIIIIIIIIIIII";
gotoxy(33,5);
switch(c)
gotoxy(3,7);
cout<<"PASSENGER NUMBER";
gotoxy(27,7);
cout<<"PASSENGER-NAME";
gotoxy(62,7);
cout<<"RESERVATION STATUS";
int i=9;
trains.open (filename,ios::in|ios::binary);
while(trains.read((char *)&r,sizeof(railway)))
{
gotoxy(10,i);
cout<<r.passno;
gotoxy(30,i);
cout<<r.name;
gotoxy(66,i);
if (strcmp(r.rstatus,"C")==0)
cout<<"CONFIRMED";
else
cout<<"WAITING LIST";
i++;
gotoxy(25,25);
getch();
trains.close();
//***************************************************************************
//***************************************************************************
void train::mod()
{
ifstream fin;
ofstream fout;
railway t;
int p,flag;
char c,filename[8];
c=select();
switch(c)
clrscr();
int found=0;
gotoxy(10,3);
cin>>p;
fin.open(filename);
fout.open("backup.dat",ios::binary);
clrscr();
gotoxy(25,3);
cout<<"MODIFICATION OF PASSENGER";
gotoxy(23,4);
while(fin.read((char *)&t,sizeof(railway)))
if(t.passno==p)
found=1;
cout<<"Record found\n\n";
fout.write((char *)&t,sizeof(t));
else
fout.write((char*)&t,sizeof(t));
fin.close();
fout.close();
remove(filename);
rename("backup.dat",filename);
getch();
clrscr();
gotoxy(20,25);
getch();
//************************************************************************
//************************************************************************
void train::cancel()
fstream trains,trains1;
int p,k=0;
char c,filename[8];
c=select();
switch(c)
case '2':strcpy(filename,"BRIT.DAT");break;
case '3':strcpy(filename,"GULF.DAT");break;
case '4':strcpy(filename,"UNIT.DAT");break;
}
clrscr();
gotoxy(10,3);
cin>>p;
trains.open(filename,ios::in|ios::binary|ios::app);
while(trains.read((char *)&r,sizeof(railway)))
k++;
trains.close();
if(p>k)
clrscr();
gotoxy(25,24);
getch();
return;
clrscr();
gotoxy(25,3);
cout<<"CANCELLATION OF TICKET";
trains.open(filename,ios::in|ios::binary);
trains1.open("TEMP.DAT",ios::out|ios::binary);
{
if(r.passno>p)
r.passno--;
trains1.write((char *)&r,sizeof(railway));
else if (r.passno<p)
trains1.write((char *)&r,sizeof(railway));
trains.close();
trains1.close();
remove(filename);
rename("TEMP.DAT",filename);
trains.open(filename,ios::in|ios::binary);
trains1.open("TEMP.DAT",ios::out|ios::binary);
if(r.passno<=5)
strcpy(r.rstatus,"C");
else
strcpy(r.rstatus,"W");
trains1.write((char *)&r,sizeof(railway));
trains.close();
trains1.close();
remove(filename);
rename("TEMP.DAT",filename);
clrscr();
gotoxy(25,24);
getch();
void train::srs()
clrscr();
cout<<"\n\n\n\t ---------R----------";
delay(125);
delay(125);
cout<<"\n\n\n\t ---------I----------";
delay(25);
cout<<"\n\n\n\t ----------L----------";
delay(125);
cout<<"\n\n\n\t ----------W----------";
delay(125);
cout<<"\n\n\n\t ----------A----------";
delay(125);
cout<<"\n\n\n\t ----------Y----------";
delay(425);
delay(425);
delay(425);
delay(425);
//************************************************************************
// Main Function
//************************************************************************
void main()
train obj;
obj.srs();
obj.srs1();
}
OUTPUT SCREENSHOTS