Вы находитесь на странице: 1из 53

Project - Railway Reservation

Harshit
Roll No. :- 12140

XII-A
Class Teacher's Sign
Computer Science Project
Government Sarvodaya Bal Vidyalaya
Examiner’s Sign Nand Nagri E-Block, Delhi-110093
I would like to thank my Computer teacher,
Mrs. Pratibha Medhavi for her guidance and
support. I would like to express my deep gratitude
towards the school management and the computer
department of providing the necessary materials
for this project. I would also like to thank my
Principal, Mr. K.P. Singh. I would like to thank
my parents and family for encouraging me during
this project completion period. I would also like to
thank my teammates for giving me the necessary
support during the project. Finally, I would like to
thank the CBSE for giving me the opportunity to
undertake this project.
Contents
S. N. Name of Topic

1. Overview of C++

2. ANSI and use of C++

3. Header files used

4. File Handling

5. Source Code

6. Output Screen

7. Conclusion

8. Bibliography
GOVT. SARVODAYA BAL
VIDYALAYA
E-Block, Nand Nagri, Delhi-93

CERTIFICATE OF MERIT

This is to certify that this project work on “Railway Reservation System” submitted by
Divyansh Pathak of class 12 'A' of Govt. Sarvodaya Bal Vidyalaya, was carried out by him
under the guidance and supervision during the academic session 2019-2020.

Subject Teacher's Signature Examiner’s Sign Principal's Signature


C++ Overview
C++ is a statically typed, compiled, general-purpose, case-sensitive, free-form
programming language that supports procedural, object-oriented, and generic
programming.

C++ is regarded as a middle-level language, as it comprises a combination of both


high-level and low-level language features.

C++ was developed by Bjarne Stroustrup starting in 1979 at Bell Labs in Murray
Hill, New Jersey, as an enhancement to the C language and originally named C
with Classes but later it was renamed C++ in 1983.

C++ is a superset of C, and that virtually any legal C program is a legal C++
program and “Its main purpose was to make writing good programs easier
and more pleasant for the individual programmer.”

Note: A programming language is said to use static typing when type


checking is performed during compile-time as opposed to run-time.

Object-Oriented Programming
C++ fully supports object-oriented programming, including the four pillars of
object-oriented development:

➢ Encapsulation
➢ Data hiding
➢ Inheritance
➢ Polymorphism
Standard Libraries
Standard C++ consists of three important parts:

➢ The core language giving all the building blocks including variables, data
types and literals, etc.
➢ The C++ Standard Library giving a rich set of functions manipulating
files, strings, etc.
➢ The Standard Template Library (STL) giving a rich set of methods
manipulating data structures, etc.

The ANSI Standard


The ANSI standard is an attempt to ensure that C++ is portable -
- that code you write for Microsoft's compiler will compile
without errors, using a compiler on a Mac, UNIX, a Windows box,
or an Alpha.

The ANSI standard has been stable for a while, and all the
major C++ compiler manufacturers support the ANSI standard.
Learning C++
The most important thing to do when learning C++ is to focus on concepts and
not get lost in language technical details.

The purpose of learning a programming language is to become a better


programmer; that is, to become more effective at designing and implementing
new systems and at maintaining old ones.

C++ supports a variety of programming styles. You can write in the style of
Fortran, C, Smalltalk, etc., in any language. Each style can achieve its aims
effectively while maintaining runtime and space efficiency.

Use of C++
C++ is used by hundreds of thousands of programmers in essentially every
application domain.

C++ is being highly used to write device drivers and other softwares that rely on
direct manipulation of hardware under real-time constraints.

C++ is widely used for teaching and research because it is clean enough for
successful teaching of basic concepts.

Anyone who has used either an Apple Macintosh or a PC running Windows has
indirectly used C++ because the primary user interfaces of these systems are
written in C++.
.:Header files used in the program:-










We analyzed and conclude that project can
be implemented using 3 major modules:-

(i) Ticket Reservation


(ii) Ticket Cancellation
(iii) Status checking

This is the module one and this comprises of


following subtasks:-

i. Checking for availability

ii. Accepting details

iii. Journey planner


Checking for availability

This is the process of checking the train’s database to check


whether seats are vacant or not. That is the whether the
ticket that will be reserved is ‘Available’ or ‘RAC’ or a
‘Waiting list’.

This includes following steps :-


a)Gathering passenger details
b)Processing the ticket request
c)Calculation of fare
d)Issuing the PNR
e)Issuing ticket details
There are three
cases:-
a) Cancellation of a confirmed ticket
involves transforming the RAC-1 to the
cancelled ticket and moving all the RAC
and Waiting list entries up by one.

b) Cancellation of a RAC involves


moving the succeeding RAC and waiting
list entries up by one.

c) Cancellation of a Waiting list just


involves the moving up by one all the
succeeding Waiting list entries.
.:Hardware Used:.
1.Processor Used
2.Ram Used: 12gb DDR4 2400mhz

3.Total Hard Disk: 1Tb or 1024gb

4.Graphics Card Used: AMD RADEON 520


[2gb DDR5]

and Intel UHD 620 Graphics[6gb DDR4]

5.Keyboard and Mouse


6. Laptop screen as monitor(15.6 inches)
7. Printer
.: ABOUT THE PROJECT:.

Project entitled “RAILWAY


RESERVATION SYSTEM” is written in
Turbo C++ IDE3.0, mainly because of its
suitability for this type of application.
Its user friendly nature and in-built
documentation, complication, error
detection, binding facilities and
interaction with other software
packages make it most powerful tool for
software development.
.:CODING:.
//************************************************
************************
// PROJECT ON RAILWAY TICKET
RESERVATION
//************************************************
************************
//REQUIRED HEADER FILES
//************************************************
************************

#include<ctype.h>
#include<conio.h>
#include<fstream.h>
#include<string.h>
#include<process.h>
#include<stdio.h>
#include<dos.h>

//************************************************
************************
//STRUCTURE CONTAINING VARIABLES FOR
RAILWAY RESERVATION.
//************************************************
************************

struct railway
{
char
name[20],sex,from[20],rstatus[2],nat[1
0];
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
//DESCRIPTION:THIS FUNCTION OPENS UP
THE MAIN MENU
// AND CALLS OTHER RELATED
FUNCTIONS.
//************************************************
************************

void train::srs1()
{
do
{
clrscr();
char choice;
gotoxy(30,2);
cout<<"******Main Menu****** ";
cout<<endl;
gotoxy(30,7);
cout<<" 1-NEW RESERVATION ";
gotoxy(30,9);
cout<<" 2-PASSENGER INFO. ";
gotoxy(30,11);
cout<<" 3-MODIFY RECORD ";
gotoxy(30,13);
cout<<" 4-DISPLAY LIST ";
gotoxy(30,15);
cout<<" 5-CANCELLATION ";
gotoxy(30,17);
cout<<" 6-QUIT TO SYSTEM ";
gotoxy(34,22);
cout<<"ENTER CHOICE:";
choice=getch();
choice=toupper(choice);
switch(choice)
{
case '1':add(); break;
case '2':pinfo(); break;
case '3':mod(); break;
case '4':list(); break;
case '5':cancel();break;
case '6':exit(1);
default:cout<<"\a";
}
}while(1);
}

//************************************************
************************
//FUNCTIONS NAME : SELECT
//DESCRIPTION :THIS FUNCTION OPENS UP
A SUB MENU FOR THE USER
//TO SELECT AN TRAIN FROM THE LIST.
//************************************************
************************

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);
cout<<"R-RETURN TO MAIN MENU\n";
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 '4':return (choice);
case '5':return(choice);
case 'R':srs1();
case 'Q':exit(1);
default:cout<<"\a" ;select();
}
}while(1);
}

//************************************************
************************
//FUNCTION NAME:GETDATA
//DESCRIPTION:FUNCTION TO GET
PASSENGER INFO. FROM
// USER FOR ADDITION AND
MODIFICATION.
//************************************************
************************

void train::getdata(int p)
{

char ch;
cout<<"\n ROUTES ARE:";
cout<<"\n 1.DELHI-JAMMU-DELHI";
cout<<"\n 2.DELHI-KANYAKUMARI-
DELHI";
cout<<"\n 3.DELHI-BOMBAY-DELHI";
cout<<"\n 4.DELHI-KOLKATA-DELHI";
cout<<"\n PLEASE SELECT YOUR ROUTE:";
cin>>r.des;
clrscr();
r.passno=p;
gotoxy(20,7);
cout<<"PASSENGER NO.:";
cout<<r.passno;
gotoxy(20,9);
cout<<"ENTER NAME OF PASSENGER:";
gets(r.name);
gotoxy(20,10);
cout<<"ENTER SEX OF PASSENGER(M/F):";
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);
cout<<"ENTER SEX OF
PASSENGER(M/F):";
cin>>r.sex;
}
gotoxy(20,11);
cout<<"ENTER AGE OF PASSENGER:";
cin>>r.age;
while(1)
{
gotoxy(34,12);
cout<<" ";
if(r.age>=4 && r.age<=100)
break;
gotoxy(34,12);
cout<<"ENTER CORRECT AGE";
getch();
gotoxy(34,12);
cout<<" ";
gotoxy(20,11);
cout<<" ";
gotoxy(20,11);
cout<<"ENTER AGE OF PASSENGER :";
cin>>r.age;
}
gotoxy(20,12);
cout<<"ENTER THE NATIONALITY :";
gets(r.nat);
gotoxy(20,13);
cout<<"STARTING POINT :";
cout<<"DELHI\n";
gotoxy(20,14);
cout<<"DESTINATION POINT :";
switch(r.des)
{
case 1:cout<<"JAMMU\n"; break;
case 2:cout<<"KANYAKUMARI\n";
break;
case 3:cout<<"BOMBAY\n"; break;
case 4:cout<<"KOLKATA\n";break;
}
gotoxy(20,16);
cout<<"TICKET NO. :";
cout<<r.passno;
}

//************************************************
************************
//FUNCTION NAME : ADD
//DESCRIPTION : FUNCTION TO ADD THE
DATA PROVIDED
// FROM GETDATA INTO THE
REQUIRED FILE.
//************************************************
************************

void train::add()
{
train temp;
int t;
fstream trains;
char c,filename[8],choice1,choice2;
do
{
t=0;
c=select();
switch(c)
{
case
'1':strcpy(filename,"IND.DAT"); break;
case
'2':strcpy(filename,"BRIT.DAT");break;
case
'3':strcpy(filename,"GULF.DAT");break;
case
'4':strcpy(filename,"UNIT.DAT");break;
case '5':strcpy(filename,"LUF.DAT");
break;
}

trains.open(filename,ios::in|ios::binary|i
os::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);
cout<<"ADDITION OF NEW
PASSENGER";
gotoxy(23,4);
cout<<"IIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
IIIII";
gotoxy(20,6);
cout<<"TRAIN NAME :";
switch(c)
{
case '1':cout<<"SHATABADI";
break;
case '2':cout<<"KOLKATA -
MAIL";break;
case '3':cout<<"SUPERFAST
EXPRES"; break;
case '4':cout<<"RAWALPINDI
EXPRES ";break;
case '5':cout<<"RAJDHANI
EXPRESS"; break;
}
getdata(t);
gotoxy(20,16);
cout<<"STATUS :";
if(t<5)
cout<<"\aCONFIRMED";
else cout<<"\aWAITING LIST";
getch();

trains.open(filename,ios::out|ios::bin
ary|ios::app);
trains.write((char*)&r,sizeof(railway
));
trains.close();
}
else
{
clrscr();
gotoxy(22,20);
cout<<"NO MORE TICKETS
AVAILABLE FOR THIS TRAIN\a";
getch();
}
gotoxy(12,25);
cout<<"\aDO YOU WISH TO MAKE ANY
MORE RESERVATION ON THIS
TRAIN(Y/N)";
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');
}

//************************************************
***************************
//FUNCTION NAME: PINFO
//DESCRIPTION: FUNCTION TO GET FULL
DETAILS OF A PARTICULAR PASSENGER
//************************************************
***************************

void train::pinfo()
{
fstream trains;
int p,k=0;
char c,filename[8];
c=select();
switch(c)
{
case '1':strcpy(filename,"IND.DAT");
break;
case
'2':strcpy(filename,"BRIT.DAT");break;
case
'3':strcpy(filename,"GULF.DAT");break;
case
'4':strcpy(filename,"UNIT.DAT");break;
case '5':strcpy(filename,"LUF.DAT");
break;
}
clrscr();
gotoxy(10,3);
cout<<"ENTER PASSENGER NUMBER :";
cin>>p;
trains.open(filename,ios::in|ios::binary|i
os::app);
while(trains.read((char
*)&r,sizeof(railway)))
{
k++;
}
trains.close();
if(p>k)
{
clrscr();
gotoxy(25,25);
cout<<"RECORD NOT FOUND.........\a";
getch();
}
else
{

trains.open(filename,ios::in|ios::binary|i
os::app);
while(trains.read((char
*)&r,sizeof(railway)))
{
if(r.passno==p)
{
clrscr();
gotoxy(27,3);
cout<<"PASSENGER INFORMATION";
gotoxy(23,6);
cout<<"TRAIN NAME :";
switch(c)
{
case '1':cout<<"SHATABADI"; break;
case '2':cout<<"KOLKATA -
MAIL";break;
case '3':cout<<"SUPERFAST EXPRES";
break;
case '4':cout<<"RAWALPINDI EXPRES
";break;
case '5':cout<<"RAJDHANI EXPRESS";
break;
}
gotoxy(23,7);
cout<<"PASSENGER NO. :";
cout<<r.passno;
gotoxy(23,9);
cout<<"NAME OF PASSENGER :";
cout<<r.name;
gotoxy(23,10);
cout<<"SEX OF PASSENGER :";
cout<<r.sex;
gotoxy(23,11);
cout<<"AGE OF PASSENGER :";
cout<<r.age;
gotoxy(23,12);
cout<<"NATIONALITY :";
cout<<r.nat;
gotoxy(23,13);
cout<<"STARTING POINT :";
cout<<"DELHI";
gotoxy(23,14);
cout<<"DESTINATION :";
switch(r.des)
{
case 1:cout<<"JAMMU\n"; break;
case 2:cout<<"KANYAKUMARI\n";
break;
case 3:cout<<"BOMBAY\n"; break;
case 4:cout<<"KOLKATA\n";break;
}
gotoxy(23,16);
cout<<"TICKET NO. :";
cout<<r.passno;
gotoxy(23,17);
cout<<"STATUS :";
if(strcmp(r.rstatus,"W")==0)
cout<<"WAITING LIST";
else cout<<"CONFIRMED";
gotoxy(5,25);
cout<<"PRESS ANY KEY TO
CONTINUE....";
getch();
}
} trains.close();
}
}

//************************************************
***************************
//FUNCTION NAME : LIST
//DESCRIPTION : FUNCTION TO SHOW
PASSENGER LIST TRAIN WISE.
//************************************************
***************************

void train::list()
{
fstream trains;
char c,filename[8];
c=select();
switch(c)
{
case '1': strcpy(filename,"IND.DAT");
break;
case '2': strcpy(filename,"BRIT.DAT");
break;
case '3': strcpy(filename,"GULF.DAT");
break;
case '4': strcpy(filename,"UNIT.DAT");
break;
case '5': strcpy(filename,"LUF.DAT");
break;
}
clrscr();
gotoxy(29,3);
cout<<"PASSENGER LIST";
gotoxy(27,4);
cout<<"IIIIIIIIIIIIIIIIIIIIIIIIIIIIII";
gotoxy(33,5);
switch(c)
{
case '1':cout<<"SHATABADI";
break;
case '2':cout<<"KOLKATA -
MAIL";break;
case '3':cout<<"SUPERFAST
EXPRES"; break;
case '4':cout<<"RAWALPINDI
EXPRES ";break;
case '5':cout<<"RAJDHANI
EXPRESS"; break;
}
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);
cout<<"\aPRESS ANY KEY YO
CONTINUE........";
getch();
trains.close();
}

//************************************************
***************************
//FUNCTION NAME : MOD
//DESCRIPTION : FUMCTION TO GET
MODIFY TICKET
// DETAILS ENTERED DURING
RESERVATION
//************************************************
***************************

void train::mod()
{
fstream trains,trains1;
railway t;
int p,flag;
char c,filename[8];
c=select();
switch(c)
{
case '1':strcpy(filename,"IND.DAT");
break;
case '2':strcpy(filename,"BRIT.DAT");
break;
case '3':strcpy(filename,"GULF.DAT");
break;
case '4':strcpy(filename,"UNIT.DAT");
break;
case '5':strcpy(filename,"LUF.DAT");
break;
}
clrscr();
int k=0;
gotoxy(10,3);
cout<<"ENTER PASSENGER NUMBER :";
cin>>p;

trains.open(filename,ios::in|ios::binary|i
os::app);
while(trains.read((char
*)&r,sizeof(railway)))
{
k++;
}
trains.close();
if(p>k)
{
clrscr();
gotoxy(25,24);
cout<<"\aPASSENGER NUMBER DOES
NOT EXIST......";
getch();
return;
}
clrscr();
gotoxy(25,3);
cout<<"MODIFICATION OF PASSENGER";
gotoxy(23,4);
cout<<" IIIIIIIIIIIIIIIIIIIIIIIIIIIII ";
getdata(p);

trains1.open("TEMP.DAT",ios::out|ios::bin
ary);
trains.seekg(0);
while(trains.read((char
*)&t,sizeof(railway)))
{
if(t.passno!=r.passno)
trains1.write((char
*)&t,sizeof(railway));
else
trains1.write((char
*)&r,sizeof(railway));
}
trains.close();
trains1.close() ;
remove(filename);
rename("TEMP.DAT",filename);
clrscr();
gotoxy(20,25);
cout<<"\aTICKET DETAILS SUCCESSFULLY
MODIFIED.....";
getch();
}

//************************************************
************************
//FUNCTION NAME : CANCEL
//DESCRIPTION : FUNCTION TO CANCEL A
TICKET.
//************************************************
************************

void train::cancel()
{
fstream trains,trains1;
int p,k=0;
char c,filename[8];
c=select();
switch(c)
{
case '1':strcpy(filename,"IND.DAT");
break;
case
'2':strcpy(filename,"BRIT.DAT");break;
case
'3':strcpy(filename,"GULF.DAT");break;
case
'4':strcpy(filename,"UNIT.DAT");break;
case '5':strcpy(filename,"LUF.DAT");
break;
}
clrscr();
gotoxy(10,3);
cout<<"ENTER PASSENGER NUMBER : ";
cin>>p;

trains.open(filename,ios::in|ios::binary|i
os::app);
while(trains.read((char
*)&r,sizeof(railway)))
{
k++;
}
trains.close();
if(p>k)
{
clrscr();
gotoxy(25,24);
cout<<"\aPASSENGER NUMBER DOES
NOT EXIST";
getch();
return;
}
clrscr();
gotoxy(25,3);
cout<<"CANCELLATION OF TICKET";

trains.open(filename,ios::in|ios::binary);

trains1.open("TEMP.DAT",ios::out|ios::bin
ary);
while (trains.read((char
*)&r,sizeof(railway)))
{
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::bin
ary);
while (trains.read((char
*)&r,sizeof(railway)))
{
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);
cout<<"\a TICKET SUCCESSFULLY
CANCELLED........";
getch();

void train::srs()
{
clrscr();
cout<<"\n\n\n\t ---------R----------";
delay(125);
cout<<"\n\n\n\t -------- A---------";
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();
}
.:OUTPUTS:.
.:Bibliography &
Conclusion:.

Conclusion

In this way a Railway Reservation system was


successfully created in C++.

Bibliography

➢ Sumita Arora – Computer text book for Class - XII


➢ http://www.cplusplus.com/forum/general/7258/
➢ https://social.msdn.microsoft.com/Forums/vstudio/en-
US/5e20d71d-a538-45b7-9cd1-b5b0d95be948/maximizing- the-c-
console-window?forum=vcgeneral
➢ https://msdn.microsoft.com/en-
us/library/windows/desktop/ms648396(v=vs.85).aspx
➢ http://www.gamedev.net/topic/201413-hiding-text-cursor-in- c-
console-applications/
➢ http://www.cplusplus.com/forum/beginner/5830/
➢ http://www.dreamincode.net/forums/topic/99121-time-delay-
output/

Вам также может понравиться