You are on page 1of 39

#include<iostream.

h>

#include<stdlib.h>

#include<ctype.h>

#include<conio.h> //for clrscr()

#include<stdio.h> //for gets()

#include<string.h>

#include<math.h> //for sqrt function

#include<fstream.h>

#include<process.h> //for exit function

void menu(); //prototype for main menu

void input_reserve(); //prototype for function taking inputs for reservation

void out_reserve(); //prototype for displaying ticket

void res_enquiry(); //porototype for reservation enquiry

void res_cancel(); //prototype for cancellation of ticket

void enquiry(); //prototype for enquiry of train

void del_train(); //prototype for delete a train

void add_train(); //prototype for add a train

void box(); //prototype for displaying box around text

void welcomepg1(); //prototype of welcome page 1

void welcomepg2(); //prototype of welcome page 2

class reservation //declaration of class reservation only for reservation purpose

{
public:

//**********data members of class reservation*************

int nop;

int trno;

int ticketno;

double pnr;

int seatno[300];

int trainno;

char tname[30];

char date[20];

double trans;

char adult;

char name[80];

int child;

char sex[10];

int age[10];

char from[30];

char to[30];

int fare;

char *chp;

//**********member functions for class reservtion***********

void input();

void output();

int city();
char clas[6];

char* coach(char*);

void show_details();

}; //end of class 'reservation'

reservation r1,r2; //objects of class reservation

class train //declaration of class train only for enquiry purpose

public:

//**********data member of class train***********

int a;

char b[50];

char c[6];

char d[6];

int t;

char tn[50];

char arr[6];

char dep[6];

//*******member functions of class train*********

void display();

void e_enter();
}; //class 'train' ends here

void main()

clrscr();

welcomepg1(); //calling ofwelcomepage 1

welcomepg2(); //calling ofwelcomepage 2

menu(); //calling of menu function

void box() //function definition for displaying box

clrscr();

for(int i=5;i<31;i++)

gotoxy(i,1);

cout<<"*";

for(int j=1;j<45;j++)

gotoxy(j,40);
cout<<"*";

for(int k=1;k<=94;k++)

gotoxy(5,k);

cout<<"*";

for(int l=1;l<=25;l++)

gotoxy(75,l);

cout<<"*";

int reservation::city() //this city function is used to

{ //display total cost of reservation

int rent;

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Delhi")==0))

rent=345;

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Mumbai")==0))
{

rent=796;

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Pune")==0))

rent=650;

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Lucknow")==0))

rent=16;

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Chandigarh")==0))

rent=248;

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Surat")==0))

rent=710;

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Howrah")==0))

rent=550;

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Jodhpur")==0))

{
rent=623;

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Jammu Tawi")==0))

rent=567;

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Patna")==0))

rent=190;

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Gorakhpur")==0))

rent=165;

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Chennai")==0))

rent=2000;

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Etawah")==0))

rent=150;

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Ahmedabad")==0))

rent=600;
}

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Puri")==0))

rent=650;

return rent;

char* reservation::coach(char* clas) //this coach function is used to

//display the berth

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Delhi")==0))

{strcpy(clas,"AC3");

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Mumbai")==0))

{strcpy(clas,"s2");

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Chandigarh")==0))

{strcpy(clas,"AC1");

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Howrah")==0))

{strcpy(clas,"s4");
}

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Patna")==0))

{strcpy(clas,"s5");

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Etawah")==0))

{strcpy(clas,"s6");

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Jodhpur")==0))

{strcpy(clas,"AC2");

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Jammu Tawi")==0))

{strcpy(clas,"s1");

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Surat")==0))

{strcpy(clas,"s8");

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Gorakhpur")==0))

{strcpy(clas,"s6");
}

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Pune")==0))

{strcpy(clas,"s3");

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Puri")==0))

{strcpy(clas,"s7");

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Ahemadabad")==0))

{strcpy(clas,"AC1");

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Lucknow")==0))

{strcpy(clas,"s4");

if((strcmpi(from,"Kanpur")==0)&&(strcmpi(to,"Chennai")==0))

{strcpy(clas,"AC3");

return clas;

void welcomepg1() //function definition of welcomepage1


{

box();

gotoxy(31,1);

textcolor(14);

cprintf("!!! WELCOME !!!");

gotoxy(23,3);

textcolor(14);

cprintf("......................................");

gotoxy(23,4);

textcolor(11);

cprintf("!!!!Project On Railway Reservation!!!!");

gotoxy(23,5);

textcolor(14);

cprintf("......................................");

gotoxy(12,10);

textcolor(3);

cprintf("Made by::");

gotoxy(13,11);

textcolor(4) ;

cprintf("PRANAV PRAKASH SAXENA Class::XII Sec.::science");

gotoxy(13,12);

textcolor(4);

cprintf("SHAURYA TRIPATHI Class::XII Sec.::science");

gotoxy(13,13);

textcolor(4) ;
cprintf("KUSHAGRA GUPTA Class::XII Sec.::science");

gotoxy(19,16);

textcolor(14);

cprintf("--------------------------------------------");

gotoxy(19,17);

textcolor(14);

cprintf("|");

gotoxy(20,17);

textcolor(3);

cprintf("Under The Guidance Of :: MR.SANDEEP TRIPATHI");

gotoxy(34,18);

textcolor(3);

cprintf("(H.O.D. Computer Science)");

gotoxy(19,19);

textcolor(14);

cprintf("--------------------------------------------");

gotoxy(64,17);

textcolor(14);

cprintf("|");

gotoxy(20,24);

textcolor(6);

cprintf("press any key to proceed further....");

getch();

clrscr();

}
void welcomepg2() //function definition of welcomepage2

box();

gotoxy(23,5);

textcolor(6);

cprintf("INDIAN.......NATIONAL........RAILWAYS");

gotoxy(23,10);

textcolor(2);

cprintf("...... W*E*L*C*O*M*E .........");

gotoxy(37,12);

textcolor(4);

cprintf("*T*O*");

gotoxy(23,14);

textcolor(3);

cprintf("----@@-----------------------@@------");

gotoxy(23,15);

textcolor(4) ;

cprintf("------KANPUR--CENTRAL--STATION-------");

gotoxy(23,16);

textcolor(5);

cprintf("----@@-----------------------@@------");

gotoxy(23,24);

textcolor(6);

cout<<"Want to continue? (Y/N)...";

char l;
cin>>l;

if((l=='y')||(l=='Y'))

clrscr();

else

exit(1);

void menu() //function definition for displaying menu

int z;

do

box(); //calling box function

gotoxy(15,3);

textcolor(15);

cprintf("*************************************************");

gotoxy(15,4);

textcolor(2);

cprintf("!!!! WELCOME TO NORTHERN INDIAN RAILWAY MENU !!!!");

gotoxy(15,5);

textcolor(15);

cprintf("*************************************************");

gotoxy(15,8);

textcolor(6);

cprintf("1 -> RESERVATION ");

gotoxy(15,10);
textcolor(3);

cprintf("2 -> VIEW RESERVATION TICKET");

gotoxy(15,12);

textcolor(4);

cprintf("3 -> RESERVATION ENQUIRY");

gotoxy(15,14);

textcolor(5);

cprintf("4 -> CANCEL RESERVATION");

gotoxy(15,16);

textcolor(15);

cprintf("5 -> TRAIN ENQUIRY");

gotoxy(15,18);

textcolor(5);

cprintf("6 -> ADD TRAIN");

gotoxy(15,20);

textcolor(15);

cprintf("7 -> DELETE TRAIN");

gotoxy(15,22);

textcolor(15);

cprintf("8 -> EXIT");

gotoxy(25,24);

textcolor(9);

cprintf("Enter your option (1-8)....");

cin>>z;

switch(z) //switch starts


{

case 1:input_reserve();

getch();

clrscr();

break;

case 2:out_reserve();

getch();

clrscr();

break;

case 3:res_enquiry();

getch();

clrscr();

break;

case 4:res_cancel();

getch();

clrscr();

break;

case 5:enquiry();

getch();

clrscr();

break;
case 6:add_train();

getch();

clrscr();

break;

case 7:del_train();

getch();

clrscr();

break;

case 8:exit(0);

break;

} //end of switch

while(z<8);

//*********function definition for taking input for reservation*********

void input_reserve()

clrscr();

ofstream f("rinfo.dat",ios::binary);
box();

r1.input();

f.write((char*)&r1,sizeof(r1));

f.close();

void reservation::input()

randomize();

gotoxy(18,3);

cprintf("----------------------------------------");

gotoxy(18,4);

cout<<"Please enter information for reservation";

gotoxy(18,5);

cprintf("----------------------------------------");

gotoxy(8,7);

textcolor(9);

cout<<"Ticket No.::";

gotoxy(8,8);

textcolor(9);

cprintf("Date::");

gotoxy(8,9);

textcolor(9);

cprintf("Train no.::");

gotoxy(8,10);

textcolor(9);
cprintf("Train Name::");

gotoxy(17,13);

cprintf("---------------------------------------");

gotoxy(18,14);

textcolor(9);

cprintf("From station");

gotoxy(34,14);

textcolor(14);

cprintf("|");

gotoxy(35,14);

textcolor(9);

cprintf("to");

gotoxy(37,14);

textcolor(14);

cprintf("|");

gotoxy(45,14);

textcolor(9);

cprintf("Station");

gotoxy(17,16);

cprintf("---------------------------------------");

gotoxy(20,7);

cin>>ticketno;

gotoxy(14,8);

gets(date);

gotoxy(19,9);
cin>>trno;

gotoxy(21,10);

gets(tname);

gotoxy(19,15);

gets(from);

gotoxy(45,15);

gets(to);

gotoxy(8,17);

textcolor(9);

cprintf("Passenger Details->");

gotoxy(30,17);

textcolor(9);

cprintf("Adults::");

cin>>adult;

gotoxy(41,17);

textcolor(9);

cprintf("Child::");

cin>>child;

gotoxy(53,17);

textcolor(9);

cprintf("Total Passengers::");

cin>>nop;

gotoxy(7,18);

cprintf("-------------------------------------------------------------------");

int y=0;
for(int i=0;i<nop;i++,y++)

gotoxy(8,19);

cout<<"Name";

gotoxy(30,19);

cout<<"Age";

gotoxy(48,19);

cout<<"Sex(m\f)";

gotoxy(7,20+y);

cout<<i+1<<".";

gotoxy(9,20+y);

gets(name);

gotoxy(30,20+y);

cin>>age[i];

gotoxy(48,20+y);

cin>>sex[i];

seatno[i]=random(5-300+1)+300;

chp=coach(clas);

fare=nop*city();

trans=random(400-124524+1)+124524;

pnr=random(50-1245687+1)+1245687;

}
//***********function definition for displaying reservation ticket***********

void out_reserve()

ifstream f1("rinfo.dat",ios::binary);

int g;

clrscr();

box();

gotoxy(18,2);

cprintf("---------------------------------------");

gotoxy(25,3); //to set X & Y axis

textcolor(6);

cprintf("!!! Have a safe & comfortable journey !!!");

gotoxy(18,4);

cprintf("---------------------------------------");

gotoxy(7,5);

textcolor(4);

cout<<"Enter Your Ticket No.:";

cin>>g;

f1.read((char*)&r2,sizeof(r2));

if(r2.ticketno==g)

gotoxy(8,8);

textcolor(6);
cout<<"Date::"<<r2.date;

gotoxy(50,8);

textcolor(6);

cout<<"Class::";

cout<<r2.chp;

gotoxy(8,9);

textcolor(6);

cout<<"Train no.::"<<r2.trno;

gotoxy(8,10);

textcolor(6);

cout<<"Train Name::"<<r2.tname;

gotoxy(17,11);

cprintf("--------------------------------------------");

gotoxy(18,12);

textcolor(6);

cprintf("Boarding At");

gotoxy(19,13);

cout<<r2.from;

gotoxy(34,12);

textcolor(14);

cprintf("|");

gotoxy(35,12);

textcolor(9);

cprintf("to");

gotoxy(37,12);
textcolor(14);

cprintf("|");

gotoxy(45,12);

textcolor(9);

cprintf("Station");

gotoxy(45,13);

cout<<r2.to;

gotoxy(17,14);

cprintf("--------------------------------------------");

int o=0;

gotoxy(6,16);

cprintf("---------------------------------------------------------------------");

for(int j=0;j<r2.nop;j++,o++)

gotoxy(8,17);

cout<<"Name";

gotoxy(28,17);

cout<<"Age";

gotoxy(40,17);

cout<<"Sex(m\f)";

gotoxy(50,17);

cout<<"Seat no.";

gotoxy(7,18+o);

cout<<j+1<<".";

gotoxy(9,18+o);
puts(r2.name);

gotoxy(29,18+o);

cout<<r2.age[j];

gotoxy(41,18+o);

cout<<r2.sex[j];

gotoxy(51,18+o);

cout<<r2.seatno[j];

gotoxy(8,23);

textcolor(2);

cout<<"T.Cash::Rs.";

cout<<r2.fare;

gotoxy(50,7);

textcolor(2);

cout<<"Trans_ID::";

cout<<r2.trans;

gotoxy(8,7);

textcolor(2);

cout<<"PNR No.::";

cout<<r2.pnr;

char b;

gotoxy(23,25);

cout<<"Press any key to continue...";

getch();
}

else

{ char a;

gotoxy(18,13);

cout<<"WRONG TICKET NUMBER";

gotoxy(18,24);

cout<<"Press any key to continue....";

getch();

f1.close();

//***********function definition to displey train information************

void train::display()

gotoxy(10,10);

cout<<"TRAIN NO.::"<<a;

gotoxy(10,12);

cout<<"TRAIN NAME::"<<b;

gotoxy(10,14);

cout<<"ARR::"<<c;

gotoxy(10,16);

cout<<"DEP::"<<d;

cout<<"Press any key to continue....";


getch();

clrscr();

void enquiry()

train t2;

int n;

clrscr();

box();

ifstream f10("enquiry.dat",ios::binary);

gotoxy(18,3);

cprintf("---------------------------------------");

gotoxy(26,4);

cout<<"TRAIN ENQUIRY";

gotoxy(18,5);

cprintf("---------------------------------------");

gotoxy(10,6);

cout<<"Enter Train No.";

cin>>n;

while(!f10.eof())

f10.read((char*)&t2,sizeof(t2));

if(t2.t==n)

{
t2.display();

getch();

}}

f10.close();

//***********function definition to add new train record************

void add_train()

int v,d=0;

train t7;

clrscr();

box();

gotoxy(15,10);

cout<<"Enter the number of trains to be added";

cin>>v;

ofstream f3("enquiry.dat",ios::app|ios::binary);

while(d<v)

t7.e_enter();

f3.write((char*)&t7,sizeof(t7));

d++;

d=0;
f3.close();

void train::e_enter()

clrscr();

box();

gotoxy(20,6);

cprintf("TRAIN ENQUIRY");

gotoxy(8,10);

cout<<"Enter Train No.::";

cin>>a;

t=a;

gotoxy(8,14);

cout<<"Enter Train Name::";

gets(b);

gotoxy(8,18);

cout<<"Enter Arrival Time::";

gets(c);

gotoxy(8,22);

cout<<"Enter Departure Time::";

gets(d);

//**********function definition to delete record of train***********


void del_train()

int g=0;

train t6;

ifstream f4("einfo.dat",ios::binary);

ofstream f5("einfo1.dat",ios::binary);

int t;

clrscr();

box();

cout<<"Enter Train No.::";

cin>>t;

while(f4)

f4.read((char*)&t6,sizeof(t6));

if(t6.a!=t)

f5.write((char*)&t6,sizeof(t6));

g=0;

else

g=1;

remove("einfo.dat");
rename("einfo1.dat","einfo.dat");

if(g==0)

gotoxy(23,8);

cout<<"Wrong Train Number Entered";

gotoxy(23,20);

cout<<"press any key to continue";

getch();

else

clrscr();

box();

gotoxy(20,15);

cout<<"Entry of Train has been removed";

gotoxy(23,23);

cout<<"Press any key to continue";

getch();

f4.close();

f5.close();

}
//***********function definition to cancel reservation************

void res_cancel()

char w;

int g=0;

reservation r6;

ifstream f7("rinfo.dat",ios::binary);

ofstream f8("rinfo1.dat",ios::binary);

int tk;

clrscr();

box();

cout<<"Enter Ticket No.::";

cin>>tk;

while(f7)

f7.read((char*)&r6,sizeof(r6));

if(r6.ticketno!=tk)

f8.write((char*)&r6,sizeof(r6));

g=0;

else

g=1;
}

remove("rinfo.dat");

rename("rinfo1.dat","rinfo.dat");

if(g==0)

gotoxy(23,10);

cout<<"Wrong Ticket Number Entered";

gotoxy(25,15);

cout<<"Press any key to continue";

getch();

else

clrscr();

box();

gotoxy(20,25);

cout<<"Your Reservation Ticket has been Cancelled";

gotoxy(19,38);

cout<<"Press any key to return to main menu";

getch();

f7.close();
f8.close();

//************function defition for reservation enquiry***********

void res_enquiry()

clrscr();

box();

int d;

reservation r20;

ifstream f9("rinfo.dat",ios::binary);

gotoxy(18,3);

cprintf("---------------------------------------");

gotoxy(26,4);

cprintf("RESERVATION ENQUIRY");

gotoxy(18,5);

cprintf("---------------------------------------");

gotoxy(7,10);

cout<<"Enter the Ticket No.";

cin>>d;

while(f9.read((char*)&r20,sizeof(r20)))

if(r20.ticketno==d)

{
gotoxy(18,13);

cout<<"YOUR RESERVATION IS CONFIRM";

gotoxy(23,25);

cout<<"Press any key to continue...";

getch();

clrscr();

box();

gotoxy(18,3);

cprintf("-----------------------------------------");

gotoxy(18,4);

cprintf("HERE IS YOUR CONFIRMED RESERVATION TICKET");

gotoxy(18,5);

cprintf("-----------------------------------------");

gotoxy(8,8);

textcolor(6);

cout<<"Date::"<<r20.date;

gotoxy(50,8);

textcolor(6);

cout<<"Class::";

cout<<r20.chp;

gotoxy(8,9);

textcolor(6);

cout<<"Train no.::"<<r20.trno;

gotoxy(8,10);

textcolor(6);
cout<<"Train Name::"<<r20.tname;

gotoxy(17,11);

cprintf("--------------------------------------------");

gotoxy(18,12);

textcolor(6);

cprintf("Boarding At");

gotoxy(19,13);

cout<<r20.from;

gotoxy(34,12);

textcolor(14);

cprintf("|");

gotoxy(35,12);

textcolor(9);

cprintf("to");

gotoxy(37,12);

textcolor(14);

cprintf("|");

gotoxy(45,12);

textcolor(9);

cprintf("Station");

gotoxy(45,13);

cout<<r20.to;

gotoxy(17,14);

cprintf("--------------------------------------------");

int o=0;
gotoxy(6,16);

cprintf("---------------------------------------------------------------------");

for(int j=0;j<r20.nop;j++,o++)

gotoxy(8,17);

cout<<"Name";

gotoxy(28,17);

cout<<"Age";

gotoxy(40,17);

cout<<"Sex(m\f)";

gotoxy(50,17);

cout<<"Seat no.";

gotoxy(7,18+o);

cout<<j+1<<".";

gotoxy(9,18+o);

puts(r20.name);

gotoxy(29,18+o);

cout<<r20.age[j];

gotoxy(41,18+o);

cout<<r20.sex[j];

gotoxy(51,18+o);

cout<<r20.seatno[j];

gotoxy(8,23);

textcolor(2);
cout<<"T.Cash::Rs.";

cout<<r20.fare;

gotoxy(50,7);

textcolor(2);

cout<<"Trans_ID::";

cout<<r20.trans;

gotoxy(8,7);

textcolor(2);

cout<<"PNR No.::";

cout<<r20.pnr;

gotoxy(23,25);

cout<<"Press any key to continue...";

getch();

else

gotoxy(18,13);

cout<<"YOUR RESERVATION IS NOT CONFIRM";

gotoxy(18,24);

cout<<"Please press any key to view your ticket....";

getch();

clrscr();

box();

}
f9.close();

//*****************************END OF PROGRAM*******************************

You might also like