You are on page 1of 41

COMPUTER PROJECT TRAIN RESERVATION

Introduction
This is a project based on train reservation. The program helps us to enter , display or alter the details of different trains. Moreover & most importantly the program helps us to reserve or cancel a train ticket. The program also helps us to know the present status of a reserved ticket, i.e whether the ticket is confirmed or not. It includes various function programs to do the above mentioned tasks. Data file handling has been effectively used in the program.

PROGRAM CODE

//PROGRAM - TRAIN RESERVATION #include<iostream.h> #include<conio.h> #include<string.h> #include<dos.h> #include<stdio.h> #include<fstream.h> #include<process.h> #include<stdlib.h>

class train { private : int trainno,nofafseat,nofasseat,noffsseat,nofacseat,nofssseat; char trainname[60],startingpoint[60],destination[60]; public : train() { trainno=0; nofafseat=0; nofasseat=0; noffsseat=0; nofacseat=0; nofssseat=0; strcpy(trainname,"/0"); strcpy(startingpoint,"/0");

} int train::returnas() { return nofasseat. int returnss().strcpy(destination. int returnaf(). //To input the details //To display the details int train::returntr() { return trainno. void display(). int returntr(). } int train::returnfs() . int returnfs(). int returnas(). } void input(). int returnac()."/0"). } int train::returnaf() { return nofafseat. }tr.

12). gotoxy(10.14).10). gotoxy(57. cout<<"ENTER THE NUMBER OF A/C FIRST CLASS SEATS". } int train::returnss() { return nofssseat.14). cout<<"ENTER THE TRAIN NUMBER ". gotoxy(10. cout<<"ENTER THE NUMBER OF A/C SECOND CLASS SEATS". gotoxy(10.{ return noffsseat. .12). gotoxy(57. gotoxy(57.10). cin>>nofafseat. } int train::returnac() { return nofacseat. cin>>trainno. } void train::input() { clrscr().

cout<<"ENTER THE TRAIN NAME".24).20). gotoxy(57.26).16). gotoxy(10. gets(destination).cin>>nofasseat.26). gotoxy(57. cout<<"ENTER THE DESTINATION ". cin>>nofssseat. cout<<"ENTER THE NUMBER OF FIRST CLASS SLEEPER SEATS". gotoxy(10.22).18). gotoxy(10. cout<<"ENTER THE NUMBER OF A/C CHAIR CAR SEATS". cout<<"ENTER THE NUMBER OF SECOND CLASS SLEEPER SEATS".18). gotoxy(10. gotoxy(10. } void train::display () . cout<<"ENTER THE STARTING POINT ". cin>>noffsseat.16). gets(trainname).22). gotoxy(57.24).20). gotoxy(57. gets(startingpoint). gotoxy(10. gotoxy(57. cin>>nofacseat. gotoxy(57.

gotoxy(10. cout<<"NO OF A/C CHAIR CLASS SEATS ".20). cout<<"NO OF A/C SECOND CLASS SEATS ". gotoxy(10.20).10). gotoxy(10. cout<<"NO OF A/C FIRST CLASS SEATS ".12). gotoxy(10.{ clrscr(). cout<<nofasseat. puts(trainname). cout<<nofafseat. . cout<<"TRAIN NAME ". gotoxy(10. cout<<trainno. cout<<nofacseat.14). gotoxy(47. gotoxy(47.22). cout<<"TRAIN NUMBER ". cout<<"NO OF SECOND CLASS SLEEPER SEATS ". gotoxy(47. gotoxy(10. gotoxy(47. gotoxy(47.16).12).18). cout<<"NO OF FIRST CLASS SLEEPER SEATS ". cout<<noffsseat.10).18). gotoxy(47. gotoxy(10.16).14).

gotoxy(10. puts(destination).22). void display().age. gotoxy(47. gotoxy(10. gotoxy(47. public: tickets(). gotoxy(10.nofac. int ret(). } class tickets { int resno. cout<<"DESTINATION ". cout<<"PRESS ANY KEY TO CONTINUE ".nofaf. cout<<nofssseat. getch().tofs.26).nofas.toas. char status[40].28). cout<<"STARTING POINT ". void reservation().noffs. }tick.toac.name[40].24).gotoxy(47. puts(startingpoint).toss.26). void cancellation().24).toaf.nofss. //To display reservation details //For ticket reservation //For ticket cancellation tickets::tickets() .

clrscr(). toaf=0. nofaf=0.{ resno=0. strcpy(name. tofs=0.ios::out). toss=0. age=0.dat". nofac=0. noffs=0. toac=0. nofas=0. ifstream fn("Ticket1. toas=0."/0").seekg(0). } int tickets::ret() { return resno. fn. . nofss=0. } void tickets::display() { int f=0."/0"). strcpy(status.

12). int n. } X: gotoxy(10.14).10) . cout<<name. gotoxy(10. gotoxy(30. cout<<age. . cout<<"PRESENT STATUS ". gotoxy(10.10).10). gotoxy(10.read((char*)&tick.sizeof(tick)).10). gotoxy(30. if(n==resno) { clrscr().12).12). cout<<"NAME ". gotoxy(10.eof()) { fn. f=1. while(!fn. gotoxy(10.if(!fn) { cout<<"ERROR IN THE FILE ". cout<<"AGE ". cin>>n. cout<<"ENTER THE RESERVATION NO ".

cout<<"PRESS ANY KEY TO CONTINUE".12). } } if(f==0) { clrscr().18). gotoxy(10. cout<<"UNRECOGINIZED RESERVATION NO !!! WANNA RETRY ?(Y/N) ".16). gotoxy(10.gotoxy(30. cout<<resno.16). cin>>a. gotoxy(10.12). cout<<"RESERVATION NUMBER ".10). cout<<"PRESS ANY KEY TO CONTINUE ". gotoxy(10. cout<<status.14). } else { gotoxy(10. gotoxy(30. . if(a=='y'||a=='Y') { clrscr(). goto X. getch(). char a.

getch(). cout<<"RESERVATION ".dat". } } fn. ofstream file. } void tickets::reservation() { clrscr(). cout<<"ENTER THE TRAIN NO: ".close().seekg(0).10). } else { clrscr(). gotoxy(10.eof()) { . cout<<"ERROR IN THE FILE ". if(!fin) { clrscr().12). cin>>tno. while(!fin.10). gotoxy(10.ios::out).f=0. gotoxy(10. ifstream fin("Train1. fin. int tno.

int z. gets(name). gotoxy(10. if(tno==z) { f=1. cout<<"AGE:". gotoxy(10. cin>>age. .ios::app). nofaf=tr.12). nofac=tr. gotoxy(10. S: clrscr().sizeof(tr)). z=tr.10). noffs=tr. } } if(f==1) { file.open("Ticket1.returnss(). clrscr(). cout<<"NAME:".returnac().10).returntr(). cout<<"SELECT THE CLASS WHICH YOU WISH TO TRAVEL".12).returnfs().dat". nofas=tr. gotoxy(10.returnaf().returnas(). nofss=tr.read((char*)&tr.fin.

gotoxy(30. cout<<"2.A/C CHAIR CAR " . puts(status). cout<<resno.SECOND CLASS SLEEPER ".FIRST CLASS SLEEPER " . cout<<"4."confirmed"). cout<<"RESERVATION NO". gotoxy(10.20). gotoxy(10. switch(c) { case 1:toaf++. gotoxy(10.18).A/C SECOND CLASS " . if((nofaf-toaf)>0) { strcpy(status.16).26).cout<<"1. gotoxy(10. . cout<<"3. cout<<"STATUS". cin>>c.24) . gotoxy(10. resno=rand(). gotoxy(30.14).A/C FIRST CLASS " . cout<<"5. getch(). int c. gotoxy(10.22).26).24). gotoxy(10.

write((char*)&tick. break.sizeof(tick)).write((char*)&tick. cout<<"RESERVATION NO". . gotoxy(10. puts(status).24). gotoxy(30. getch(). gotoxy(30.24) . } else { strcpy(status. puts(status).26).sizeof(tick)).24). } case 2:toas++. resno=rand().26).file.24). cout<<resno.26). cout<<"STATUS". gotoxy(10."confirmed"). gotoxy(10. if((nofas-toas)>0) { strcpy(status. file. gotoxy(10. break. cout<<"STATUS". gotoxy(30."pending").

write((char*)&tick. resno=rand(). cout<<"RESERVATION NO".cout<<"RESERVATION NO". break.sizeof(tick)). file. cout<<resno. cout<<resno.26).26). file.24). break. gotoxy(30. } else { strcpy(status.26). cout<<"STATUS". gotoxy(10.24). getch().24) . puts(status). if((noffs-tofs)>0) { strcpy(status.sizeof(tick)).write((char*)&tick. gotoxy(30. } case 3:tofs++. gotoxy(10. gotoxy(10. getch(). ."confirmed")."pending"). gotoxy(30.

cout<<"STATUS".26). getch().sizeof(tick)).26).26). cout<<resno. } else { strcpy(status. break.24). cout<<resno. . } case 4:toac++. gotoxy(10.26). file."pending").sizeof(tick)). cout<<"STATUS".write((char*)&tick. cout<<"RESERVATION NO".24). getch().24). gotoxy(30. gotoxy(30. break. gotoxy(30. gotoxy(10. gotoxy(10. gotoxy(30. cout<<"RESERVATION NO". puts(status). file. puts(status). resno=rand().write((char*)&tick.

gotoxy(30.26). gotoxy(10. getch().24) . cout<<"STATUS".sizeof(tick)). gotoxy(10."confirmed"). gotoxy(30. break. cout<<resno. gotoxy(10. gotoxy(10.sizeof(tick)). cout<<resno. getch(). file."pending").24). puts(status). cout<<"STATUS".write((char*)&tick. cout<<"RESERVATION NO". gotoxy(30.if((nofac-toac)>0) { strcpy(status.26). gotoxy(30.26). cout<<"RESERVATION NO". file.24).write((char*)&tick. .26). } else { strcpy(status. puts(status).24).

puts(status). gotoxy(10. cout<<resno. } case 5:toss++. file. gotoxy(30. puts(status).26). gotoxy(10. break. gotoxy(10. cout<<"STATUS".sizeof(tick)).24) .break.26). .write((char*)&tick."confirmed"). gotoxy(10.24). gotoxy(30.26). cout<<"STATUS". } else { strcpy(status.24). resno=rand(). cout<<"RESERVATION NO"."pending"). gotoxy(30. cout<<"RESERVATION NO". getch(). if((nofss-toss)>0) { strcpy(status.24).

30).gotoxy(30. } } gotoxy(10. cout<<"ERROR IN THE TRAIN NUMBER ENTERED !!!".close(). break. delay(1000).28). } void tickets::cancellation() . cin>>n. } } } if(f==0) {clrscr().sizeof(tick)). cout<<"DO YOU WISH TO CONTINUE BOOKING TICKETS (Y/N) ? ". file. } file. char n. gotoxy(10. getch().write((char*)&tick. cout<<resno.10). if(n=='y'||n=='Y') { goto S. gotoxy(10.26). getch().

} while(!fin.read((char*)&tick. ifstream fin. fin.sizeof(tick)).dat".sizeof(tick)). z=ret().open("Ticket1.seekg(0). fin. } if(z==r) { f=1. } } . int r. file. ofstream file.ios::app). gotoxy(10.10). if(!fin) { cout<<"ERROR IN THE FILE !!!".f=0. cin>>r. int z.write((char*)&tick. if(z!=r) { file.ios::out). cout<<"ENTER THE RESERVATION NO ".{clrscr().dat".eof()) { fin.open("Temp1.

.dat"). fin. remove("Ticket1. } else { gotoxy(10.j..no.12). getch(). rename("Temp1.close(). delay(1500). getch(). .r=1000.i.12). gotoxy(33.22).file. cout<<"WELCOME". gotoxy(25. Z: clrscr().dat").close(). cout<<"NO SUCH RESERVATION IS MADE !!! PLEASE RETRY. if(f==0) {gotoxy(10.8) . } } void main() { int ch."Ticket1. clrscr().. cout<<"RESERVATION CANCELLED".dat". delay(1000).".

gotoxy(20. cout<<"6. fin. gotoxy(20. cout<<"4.27).25). gotoxy(20. gotoxy(20.UPDATE TRAIN DETAILS ".17). cout<<"ENTER YOUR CHOICE: ". . gotoxy(20.TRAIN DETAILS". cout<<"1. gotoxy(20. cin>>ch.dat". cout<<"3. gotoxy(20.15) . gotoxy(25.CANCELLING A TICKET". if(!fin) { clrscr().ios::out). switch(ch) { case 1:ifstream fin("Train1. char n. cout<<"5.21). textcolor(1).19).cout<<"RAILWAY TICKET RESERVATION".EXIT".RESERVING A TICKET ". cout<<"2.DISPLAY THE PRESENT TICKET STATUS ".9). clrscr().23). cout<<"==========================".seekg(0).

.read((char*)&tr.input(). cin>>j..ios::app).gotoxy(10. cout<<"ERROR IN THE FILE !!!"...10).. ... delay(2000)..write((char*)&tr. while(!fin. cout<<"CHECKING PLEASE WAIT. gotoxy(10.dat". cout<<"ENTER THE PASSWORD " .. } } fin.".30). } else {clrscr()..eof()) { fin. fout.. fout. gotoxy(20.10).close()...sizeof(tr)). goto Z....close().display().30).. tr. gotoxy(20. case 2:clrscr().. tr.sizeof(tr)). if(j==r) { Y: ofstream fout("Train1...

goto Z.cout<<"DO YOU WISH TO CONTINUE UPDATING ?(Y/N)". goto Z. goto Z. case 5:tick.reservation(). textcolor(WHITE).display(). if(n=='y'||n=='Y') goto Y. case 3:tick. } getch(). case 4:tick. case 6:exit(0).cancellation(). goto Z. cin>>n. } . } else goto Z.

SAMPLE OUTPUT .

TRAIN DETAILS 2.CANCELLING A TICKET 5.DISPLAY THE PRESENT TICKET STATUS 6.UPDATE TRAIN DETAILS 3.EXIT ENTER YOUR CHOICE:2 .RAILWAY TICKET RESERVATION ========================== 1.RESERVING A TICKET 4.

ENTER THE PASSWORD 1000 CHECKING PLEASE WAIT .. .

ENTER THE TRAIN NUMBER 2700 ENTER THE NUMBER OF A/C FIRST CLASS SEATS 300 ENTER THE NUMBER OF A/C SECOND CLASS SEATS 450 ENTER THE NUMBER OF FIRST CLASS SLEEPER SEATS 600 ENTER THE NUMBER OF A/C CHAIR CAR SEATS 450 ENTER THE NUMBER OF SECOND CLASS SLEEPER SEATS 600 ENTER THE TRAIN NAME Dreamz Xpress ENTER THE STARTING POINT Alwaye ENTER THE DESTINATION Marmagoa DO YOU WISH TO CONTINUE UPDATING ?(Y/N)N .

UPDATE TRAIN DETAILS 3.DISPLAY THE PRESENT TICKET STATUS 6.EXIT ENTER YOUR CHOICE: 1 .RESERVING A TICKET 4.CANCELLING A TICKET 5.RAILWAY TICKET RESERVATION ========================== 1.TRAIN DETAILS 2.

TRAIN NUMBER 2700 TRAIN NAME Dreamz Xpress NO OF A/C FIRST CLASS SEATS 300 NO OF A/C SECOND CLASS SEATS 450 NO OF FIRST CLASS SLEEPER SEATS 600 NO OF A/C CHAIR CLASS SEATS 450 NO OF SECOND CLASS SLEEPER SEATS 600 STARTING POINT Alwaye DESTINATION Marmagoa PRESS ANY KEY TO CONTINUE .

TRAIN DETAILS 2.EXIT ENTER YOUR CHOICE: 3 .UPDATE TRAIN DETAILS 3.DISPLAY THE PRESENT TICKET STATUS 6.CANCELLING A TICKET 5.RESERVING A TICKET 4.RAILWAY TICKET RESERVATION ========================== 1.

RESERVATION ENTER THE TRAIN NO: 2700 .

FIRST CLASS SLEEPER 4.SELECT THE CLASS WHICH YOU WISH TO TRAVEL 1.A/C SECOND CLASS 3.SECOND CLASS SLEEPER 2 STATUS confirmed RESERVATION NO 346 DO YOU WISH TO CONTINUE BOOKING TICKETS (Y/N) ? N .A/C FIRST CLASS 2.A/C CHAIR CAR 5.

TRAIN DETAILS 2.RESERVING A TICKET 4.RAILWAY TICKET RESERVATION ========================== 1.EXIT ENTER YOUR CHOICE: 5 .CANCELLING A TICKET 5.DISPLAY THE PRESENT TICKET STATUS 6.UPDATE TRAIN DETAILS 3.

ENTER THE RESERVATION NO 346 .

NAME Sudhir Mishra AGE 45 PRESENT STATUS confirmed RESERVATION NUMBER 346 PRESS ANY KEY TO CONTINUE .

RESERVING A TICKET 4.TRAIN DETAILS 2.RAILWAY TICKET RESERVATION ========================== 1.CANCELLING A TICKET 5.EXIT ENTER YOUR CHOICE: 4 .UPDATE TRAIN DETAILS 3.DISPLAY THE PRESENT TICKET STATUS 6.

ENTER THE RESERVATION NO 346 RESERVATION CANCELLED .

EXIT ENTER YOUR CHOICE: 6 .UPDATE TRAIN DETAILS 3.TRAIN DETAILS 2.CANCELLING A TICKET 5.RESERVING A TICKET 4.DISPLAY THE PRESENT TICKET STATUS 6.RAILWAY TICKET RESERVATION ========================== 1.