0% found this document useful (0 votes)
68 views75 pages

K Arya

The document describes an online railway ticket reservation system. It includes: 1. Key features of the system like login, searching trains, booking tickets, checking PNR status, refunds, and admin functions. 2. Entity relationship (ER) and data flow diagrams (DFD) that illustrate the relationships between entities like passengers, tickets, trains etc. 3. Class, use case, activity, and sequence diagrams that model different aspects of the system's design and functionality.

Uploaded by

Kanchan Arya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views75 pages

K Arya

The document describes an online railway ticket reservation system. It includes: 1. Key features of the system like login, searching trains, booking tickets, checking PNR status, refunds, and admin functions. 2. Entity relationship (ER) and data flow diagrams (DFD) that illustrate the relationships between entities like passengers, tickets, trains etc. 3. Class, use case, activity, and sequence diagrams that model different aspects of the system's design and functionality.

Uploaded by

Kanchan Arya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 75

Online Railway Ticket Reservation System

Online Railway ticket reservation is very useful nowadays. This is very


important to design a good-working system software for ticket booking
and related transactions. To design it, full-track documentation of
models(ER, DFD, Class, Use-case, Activity, Sequence) is required as per
as software development is concerned.

Features of the System:


The Reservation system should contain the following features: 
1. If a passenger wants to reserve ticket(s), firstly, he/she has to
log in to the Railway system with valid credentials. Then, the
passenger has to provide his/her details with the date of the
journey, names of the passengers and their details, origin
station details, destination station details, and the class type
of the required ticket(s).
2. The Railway Reservation System will provide the available
Train-list, and Seat-availability, via-details.
3. To book a ticket passengers can pay through online/offline
mode. After successful payment of the ticket fare the System
will generate the ticket and PNR no. will be given to the
passenger. The System also keeps the payment details and
sends them to the system Admin.
4. The Passenger can check PNR status (confirmed, RAC,
waiting list) by entering the PNR no. into the Reservation
system.
5. The Reservation system should store all train details, fare
details (by zone, class, and date wise), PNR no, date of
trains, etc. This maintenance should be controlled by the
Admin. 
6. The System also has refund rules which have a date of
reservation, ticket fare, and refundable percentage. The
passenger can simply cancel the ticket(s) by entering the
PNR no and a cancel ticket request. After cancelation, the
Admin will pass the refundable amount to the System and the
System will give the refundable amount to the passenger.
7. Required Diagrams:
8. Entity Relationship(ER) Diagram:  
9. ER diagram displays the relations between the various
entities(classes and their attributes) stored in the database.
ER diagrams are very important for any database project.
This diagram shows the communication between entities
and their attributes.

The above ER diagram illustrates the key information about the


railway reservation system, including entities like PAX_info,
Login_credentials, Ticket_reservation, refund_rule, via_details,
train_fare, Train, Seat_availability, Class, Zone, station,
pay_info. This diagram also shows the relationships between
entities.
Entities and their attributes are:
PAX_info: Attributes of PAX_info entity are  Passenger_id
(primarykey) ,SRL_no ,PAX_name ,PAX_age ,PAX_sex ,fare,se
at_no.
 Login_credentials: Attributes of Login_credentials entity are
login_id(PK) , password.
 Ticket_reservation: Attributes of Ticket_reservation entity
are PNR_no(pk),to-date, from-date, to-km, from-km, to-
station, from-station, Train_code.
  Refund_rule: Attributes of  refund_rule entity are to-time,
from-time, refundable-amt.
 via_details: Attributes of via_details entity are
Details_id(PK), Train_code, via_station_code,
km_from_origin, Reach_time.
 train_fare: Attributes of train_fare entity are to-date, from-
date, to-km, from-km, Fare, Class_id.
 Train: Attributes of Train entity are Train_code(PK),
Distance, Train_name, Start_time, End_time,
Start_station_code, End_station_code, Frequency.
 Seat_availability: Attributes of Seat_availability entity are
Train_code, Class_code, and Number of seats.
 Class: Attributes of Class entity are Class_id(PK),
coach_prefix, class_code, Class_name, seat_per_coach.
 Zone: Attributes of Zone entity are zone_id(PK),
Zone_name,Zone_code.
 Station: Attributes of station entity are
Station_id(PK),Station_code,station_name, zone_id.
 Pay_info: Attributes of Pay_info entity are payment_id(PK),
pay_mode, amount, pay_date, srl-no, PNR_no, inst_type,
inst_amt.
Relationships between Entities:
 One-to-one relation: PAX_info to login_credentials ,
PAX_info to refund_rule, Train to Via_details, Class to
train_fare, PAX_info to pay_info.
 Many-to-one relation: PAX_info to ticket_reservation, Zone
to the station, Class to seat_availability.
 Many-to-many: Train to the station, Train to class. 
Data-Flow Diagram(DFD): 
This diagram represents various operations by dataflow
movement

 Level 1 DFD:
Class Diagram: 
These diagrams describe the operation and attributes of a class
with imposed constraints in the system. In this article the classes
to be considered are ‘payment’, ‘train’, ‘passenger’, ‘ticket’,
‘railway reservation system’, ‘admin’. The description of the
classes is given below.

Class Attributes Processes

Payment amount ticketGeneration

train code, train name,


Train                        —
frequency

login, search Train, modify the


form,
passenger PAX_id, name,age,sex
pay charges, book tickets now
ticket, cancel tickets

PNR_no, status, payment type,


train code search train,
ticket new Ticket, delete tickets
date of journey

railway
reservation system response
system

formDetails, cancellationForm,
Admin ID, name
refundAmt
Use-Case Diagram: 
By using use case diagrams, the interactions between a system
and the users within that system will be represented.
Use-Case Descriptions:
The relationship between the actors and the use cases of the
online Railway reservation system is given below–>
1. Passenger Entity: Use cases of passengers are login, ticket
availability, Filling the form, Book ticket, Canceling ticket, and
Refund money.   
2. Railway Reservation System: Use cases of the Railway
Reservation System are login, ticket availability, Fill the form,
Book ticket, Cancel ticket, and Refunding money.   
3. Admin: use cases of Admin are Print ticket, refund money.
Admin also controls the whole Railway Reservation System
in different cases.
Activity Diagram: 
This diagram shows the flow of processes from one to another
activity.
Sequence Diagram: 
This diagram shows how and in which order a group of objects
works together in a system. This is an interactive diagram and
this is mostly used by software developers.
This Railway Reservation
System in C was build and
run under Code::Blocks IDE.
To run this Railway Reservation System in C  make
sure that you have a Code Blocks or any platform of
C installed in your computer. Please scroll down and
click the download button to obtain a free copy of the
Railway Reservation System project.

ABOUT PROJECT PROJECT DETAILS

Project Name : Railway Reservation System

Project Platform : C/C++

Programming Language Used: C Programming Language

Developer Name : itsourcecode.com

IDE Tool (Recommended): Dev-C++/Codeblocks

Project Type : Desktop Application


ABOUT PROJECT PROJECT DETAILS

Database: Stores data in .DAT file

Railway Reservation System in C with Source Code Overview

Railway Reservation System in C Steps On


How To Run The Project
Time needed: 5 minutes.

Here’s the step’s on how to run a  Railway


Reservation System in C with Source Code.

Step 1: Extract file.


Next, after you finished download the source code,
extract the zip file.

Step 2: Open CodeBlocks


After that, After extracting the zip file, open your
“CodeBlocks IDE”.

Step 3: Open Project.


Then, open file tab and Open File after that open
folder RRS-IN-C then click the “main“.

Step 4: Run Project


Lastly, Open build tab and select build and run or you
can use key F9.
 Step 5: The actual code.
Finally, You are free to copy the given source
code below or download the downloadable source
code given.

 Function to create main menu in the system.


void mainmenu(char user[20],char pw[20]){
char choice;
check=0;
retry:
system("cls");
printf("\n\t\t WELCOME, %s.\n",user);
printf("\n\t\t|\t CHOOSE WHAT TO DO\t\t\t |" );
printf("\n\t\t|\t _______________________________\
t |");
printf("\n\t\t|\t| 1. Book new tickets\t\t|\t |" );
printf("\n\t\t|\t| 2. Cancel booked trips\t|\t |" );
printf("\n\t\t|\t| 3. Check upcoming travels\t|\t |" );
printf("\n\t\t|\t| 4. Check waitlist\t\t|\t |" );
printf("\n\t\t|\t| 5. Logout\t\t |\t |" );
 Function to create a sign up.

void signup(){
char user[20],pw[20],c;
char dir[100]="./railway dbs/";
int len,ch,i;
FILE *fptr;
redouser:
strcpy(dir,"./railway dbs/");
ch=0;
system("cls");
printf("\n\t\t __________________________");
printf("\n\t\t|\t\t\t |");
printf("\n\t\t|\t SIGN UP\t |");
printf("\n\t\t|__________________________|");
printf("\n\n\t\tNOTE : Username should consist of 6-16
characters\n\t\t [Only numbers and alphabets without
space]");
printf("\n\n\t\tUSERNAME : ");
scanf("\n");
scanf("%[^\n]%*c",user);
len=strlen(user);
if(len>16 || len<6)
{
printf("\n\t\tWARNING : Username does not follow
conditions. Retry.");

 The function to start up main window

void startup(){
char choice;
system("cls");
system("color 1F");
printf("\n\t\t\t WELCOME TO MANILA TRAIN
RAILWAY SERVICE\n\n" );
printf("\n\n\t\tPress any to continue...... " ); getch();
redo:
system("cls");
printf("\n\t\t\t CHOOSE YOUR OPTION\t\t\t " );

printf("\n\t\t\t 1. Login to Existing Account\t\t" );


printf("\n\t\t\t 2. Create New Account\t\t" );
printf("\n\t\t\t3. Exit\t\t ");
choice=getch();
if(choice!='1'&&choice!='2'&&choice!='3')
{
printf("\n\t\tWarning : INVALID INPUT. TRY
AGAIN\n");
delay(1);
goto redo;
}
else
{
if(choice=='1')
login();
else if(choice=='2')
signup();
else if(choice=='3')
shutdown();
}
}
Function to search new booking
int* search(char user[20],ch

 Function to search new booking

int* search(char user[20],char pw[20],int c){


int
choice,origin,dest,n_trains,i,*lst,*index=malloc(3*sizeof(i
nt));
char option,ch;
if(c==0){
redo_origin :
system("cls");
printf("\n\t\t\t NEW BOOKING\t");
printf("\n\n\t\t NOTE : Choose Where you wish to
travel from.\n");
display_stations();
printf("\n\t\t CHOICE : ");
scanf("%d",&choice);
if(choice<=0 || choice>34){
printf("\n\t\t WARNING : INVALID OPTION.
RETRY.");
delay(1);
goto redo_origin;
}
 Function to check up coming travels.

void check_upcoming(char user[20],char pw[20]){


FILE *in;
char dir[100]="./railway dbs/",ps[20];
struct passenger p;
int i=0;
strcat(dir,user);strcat(dir,".txt");
in = fopen(dir,"r");
system("cls");
printf("\n\t\t| UPCOMING TRAVELS\t |" );
fscanf(in,"%s ",&ps);

 The function to check waiting list.

void check_waitlist(char user[20],char pw[20]){


FILE *in;
char dir[100]="./railway dbs/",ps[20];
struct passenger p;
int i=0;
strcat(dir,user);strcat(dir,".txt");
in = fopen(dir,"r");
system("cls");
printf("\n\t\t|\tWAITING LIST\t |" );
fscanf(in,"%s ",&ps);
Function to cancel booking
void cancelbooking(char user[20],char pw[20]){
FILE *in,*out;
char dir[100]="./railway dbs/",ps[20],c,dir2[100];
struct passenger p,r;
struct waitlist *t,*s;
int i=0,n,index;
strcat(dir,user);strcat(dir,".txt");
redoview:
i=0;
in = fopen(dir,"r");
system("cls");
printf("\n\t\t|\tCANCEL BOOKING\t |");
fscanf(in,"%s",&ps);

Conclusion
This Railway Reservation System Project in C with
Source Code is only a project made for school
requirement purposes only . A Railway Reservation
System in C language was created specifically for a
semester project.

It aims to give beginners a good understanding of


programming small to large projects by imparting
general workable and practical information about C.
You can download this program and modify it to suit
your client requirements, since this is a student
project it means you cannot really expect 100%
functionality from this.

Online Railway Ticket Reservation System


Online Railway ticket reservation is very useful nowadays. This is very
important to design a good-working system software for ticket booking
and related transactions. To design it, full-track documentation of
models(ER, DFD, Class, Use-case, Activity, Sequence) is required as per
as software development is concerned.

Features of the System:


The Reservation system should contain the following features: 
1. If a passenger wants to reserve ticket(s), firstly, he/she has to
log in to the Railway system with valid credentials. Then, the
passenger has to provide his/her details with the date of the
journey, names of the passengers and their details, origin
station details, destination station details, and the class type
of the required ticket(s).
2. The Railway Reservation System will provide the available
Train-list, and Seat-availability, via-details.
3. To book a ticket passengers can pay through online/offline
mode. After successful payment of the ticket fare the System
will generate the ticket and PNR no. will be given to the
passenger. The System also keeps the payment details and
sends them to the system Admin.
4. The Passenger can check PNR status (confirmed, RAC,
waiting list) by entering the PNR no. into the Reservation
system.
5. The Reservation system should store all train details, fare
details (by zone, class, and date wise), PNR no, date of
trains, etc. This maintenance should be controlled by the
Admin. 
6. The System also has refund rules which have a date of
reservation, ticket fare, and refundable percentage. The
passenger can simply cancel the ticket(s) by entering the
PNR no and a cancel ticket request. After cancelation, the
Admin will pass the refundable amount to the System and the
System will give the refundable amount to the passenger.
7. Required Diagrams:
8. Entity Relationship(ER) Diagram:  
9. ER diagram displays the relations between the various
entities(classes and their attributes) stored in the database.
ER diagrams are very important for any database project.
This diagram shows the communication between entities
and their attributes.
The above ER diagram illustrates the key information about the
railway reservation system, including entities like PAX_info,
Login_credentials, Ticket_reservation, refund_rule, via_details,
train_fare, Train, Seat_availability, Class, Zone, station,
pay_info. This diagram also shows the relationships between
entities.
Entities and their attributes are:
PAX_info: Attributes of PAX_info entity are  Passenger_id
(primarykey) ,SRL_no ,PAX_name ,PAX_age ,PAX_sex ,fare,se
at_no.
 Login_credentials: Attributes of Login_credentials entity are
login_id(PK) , password.
 Ticket_reservation: Attributes of Ticket_reservation entity
are PNR_no(pk),to-date, from-date, to-km, from-km, to-
station, from-station, Train_code.
  Refund_rule: Attributes of  refund_rule entity are to-time,
from-time, refundable-amt.
 via_details: Attributes of via_details entity are
Details_id(PK), Train_code, via_station_code,
km_from_origin, Reach_time.
 train_fare: Attributes of train_fare entity are to-date, from-
date, to-km, from-km, Fare, Class_id.
 Train: Attributes of Train entity are Train_code(PK),
Distance, Train_name, Start_time, End_time,
Start_station_code, End_station_code, Frequency.
 Seat_availability: Attributes of Seat_availability entity are
Train_code, Class_code, and Number of seats.
 Class: Attributes of Class entity are Class_id(PK),
coach_prefix, class_code, Class_name, seat_per_coach.
 Zone: Attributes of Zone entity are zone_id(PK),
Zone_name,Zone_code.
 Station: Attributes of station entity are
Station_id(PK),Station_code,station_name, zone_id.
 Pay_info: Attributes of Pay_info entity are payment_id(PK),
pay_mode, amount, pay_date, srl-no, PNR_no, inst_type,
inst_amt.
Relationships between Entities:
 One-to-one relation: PAX_info to login_credentials ,
PAX_info to refund_rule, Train to Via_details, Class to
train_fare, PAX_info to pay_info.
 Many-to-one relation: PAX_info to ticket_reservation, Zone
to the station, Class to seat_availability.
 Many-to-many: Train to the station, Train to class. 
Data-Flow Diagram(DFD): 
This diagram represents various operations by dataflow
movement

 Level 1 DFD:
Class Diagram: 
These diagrams describe the operation and attributes of a class
with imposed constraints in the system. In this article the classes
to be considered are ‘payment’, ‘train’, ‘passenger’, ‘ticket’,
‘railway reservation system’, ‘admin’. The description of the
classes is given below.

Class Attributes Processes

Payment amount ticketGeneration

train code, train name,


Train                        —
frequency

login, search Train, modify the


form,
passenger PAX_id, name,age,sex
pay charges, book tickets now
ticket, cancel tickets

PNR_no, status, payment type,


train code search train,
ticket new Ticket, delete tickets
date of journey

railway
reservation system response
system

formDetails, cancellationForm,
Admin ID, name
refundAmt
Use-Case Diagram: 
By using use case diagrams, the interactions between a system
and the users within that system will be represented.
Use-Case Descriptions:
The relationship between the actors and the use cases of the
online Railway reservation system is given below–>
1. Passenger Entity: Use cases of passengers are login, ticket
availability, Filling the form, Book ticket, Canceling ticket, and
Refund money.   
2. Railway Reservation System: Use cases of the Railway
Reservation System are login, ticket availability, Fill the form,
Book ticket, Cancel ticket, and Refunding money.   
3. Admin: use cases of Admin are Print ticket, refund money.
Admin also controls the whole Railway Reservation System
in different cases.
Activity Diagram: 
This diagram shows the flow of processes from one to another
activity.
Sequence Diagram: 
This diagram shows how and in which order a group of objects
works together in a system. This is an interactive diagram and
this is mostly used by software developers.
This Railway Reservation
System in C was build and
run under Code::Blocks IDE.
To run this Railway Reservation System in C  make
sure that you have a Code Blocks or any platform of
C installed in your computer. Please scroll down and
click the download button to obtain a free copy of the
Railway Reservation System project.

ABOUT PROJECT PROJECT DETAILS

Project Name : Railway Reservation System

Project Platform : C/C++

Programming Language Used: C Programming Language

Developer Name : itsourcecode.com

IDE Tool (Recommended): Dev-C++/Codeblocks

Project Type : Desktop Application


ABOUT PROJECT PROJECT DETAILS

Database: Stores data in .DAT file

Railway Reservation System in C with Source Code Overview

Railway Reservation System in C Steps On


How To Run The Project
Time needed: 5 minutes.

Here’s the step’s on how to run a  Railway


Reservation System in C with Source Code.

Step 1: Extract file.


Next, after you finished download the source code,
extract the zip file.

Step 2: Open CodeBlocks


After that, After extracting the zip file, open your
“CodeBlocks IDE”.

Step 3: Open Project.


Then, open file tab and Open File after that open
folder RRS-IN-C then click the “main“.

Step 4: Run Project


Lastly, Open build tab and select build and run or you
can use key F9.
 Step 5: The actual code.
Finally, You are free to copy the given source
code below or download the downloadable source
code given.

 Function to create main menu in the system.


void mainmenu(char user[20],char pw[20]){
char choice;
check=0;
retry:
system("cls");
printf("\n\t\t WELCOME, %s.\n",user);
printf("\n\t\t|\t CHOOSE WHAT TO DO\t\t\t |" );
printf("\n\t\t|\t _______________________________\
t |");
printf("\n\t\t|\t| 1. Book new tickets\t\t|\t |" );
printf("\n\t\t|\t| 2. Cancel booked trips\t|\t |" );
printf("\n\t\t|\t| 3. Check upcoming travels\t|\t |" );
printf("\n\t\t|\t| 4. Check waitlist\t\t|\t |" );
printf("\n\t\t|\t| 5. Logout\t\t |\t |" );
 Function to create a sign up.

void signup(){
char user[20],pw[20],c;
char dir[100]="./railway dbs/";
int len,ch,i;
FILE *fptr;
redouser:
strcpy(dir,"./railway dbs/");
ch=0;
system("cls");
printf("\n\t\t __________________________");
printf("\n\t\t|\t\t\t |");
printf("\n\t\t|\t SIGN UP\t |");
printf("\n\t\t|__________________________|");
printf("\n\n\t\tNOTE : Username should consist of 6-16
characters\n\t\t [Only numbers and alphabets without
space]");
printf("\n\n\t\tUSERNAME : ");
scanf("\n");
scanf("%[^\n]%*c",user);
len=strlen(user);
if(len>16 || len<6)
{
printf("\n\t\tWARNING : Username does not follow
conditions. Retry.");

 The function to start up main window

void startup(){
char choice;
system("cls");
system("color 1F");
printf("\n\t\t\t WELCOME TO MANILA TRAIN
RAILWAY SERVICE\n\n" );
printf("\n\n\t\tPress any to continue...... " ); getch();
redo:
system("cls");
printf("\n\t\t\t CHOOSE YOUR OPTION\t\t\t " );

printf("\n\t\t\t 1. Login to Existing Account\t\t" );


printf("\n\t\t\t 2. Create New Account\t\t" );
printf("\n\t\t\t3. Exit\t\t ");
choice=getch();
if(choice!='1'&&choice!='2'&&choice!='3')
{
printf("\n\t\tWarning : INVALID INPUT. TRY
AGAIN\n");
delay(1);
goto redo;
}
else
{
if(choice=='1')
login();
else if(choice=='2')
signup();
else if(choice=='3')
shutdown();
}
}
Function to search new booking
int* search(char user[20],ch

 Function to search new booking

int* search(char user[20],char pw[20],int c){


int
choice,origin,dest,n_trains,i,*lst,*index=malloc(3*sizeof(i
nt));
char option,ch;
if(c==0){
redo_origin :
system("cls");
printf("\n\t\t\t NEW BOOKING\t");
printf("\n\n\t\t NOTE : Choose Where you wish to
travel from.\n");
display_stations();
printf("\n\t\t CHOICE : ");
scanf("%d",&choice);
if(choice<=0 || choice>34){
printf("\n\t\t WARNING : INVALID OPTION.
RETRY.");
delay(1);
goto redo_origin;
}
 Function to check up coming travels.

void check_upcoming(char user[20],char pw[20]){


FILE *in;
char dir[100]="./railway dbs/",ps[20];
struct passenger p;
int i=0;
strcat(dir,user);strcat(dir,".txt");
in = fopen(dir,"r");
system("cls");
printf("\n\t\t| UPCOMING TRAVELS\t |" );
fscanf(in,"%s ",&ps);

 The function to check waiting list.

void check_waitlist(char user[20],char pw[20]){


FILE *in;
char dir[100]="./railway dbs/",ps[20];
struct passenger p;
int i=0;
strcat(dir,user);strcat(dir,".txt");
in = fopen(dir,"r");
system("cls");
printf("\n\t\t|\tWAITING LIST\t |" );
fscanf(in,"%s ",&ps);
Function to cancel booking
void cancelbooking(char user[20],char pw[20]){
FILE *in,*out;
char dir[100]="./railway dbs/",ps[20],c,dir2[100];
struct passenger p,r;
struct waitlist *t,*s;
int i=0,n,index;
strcat(dir,user);strcat(dir,".txt");
redoview:
i=0;
in = fopen(dir,"r");
system("cls");
printf("\n\t\t|\tCANCEL BOOKING\t |");
fscanf(in,"%s",&ps);

Conclusion
This Railway Reservation System Project in C with
Source Code is only a project made for school
requirement purposes only . A Railway Reservation
System in C language was created specifically for a
semester project.

It aims to give beginners a good understanding of


programming small to large projects by imparting
general workable and practical information about C.
You can download this program and modify it to suit
your client requirements, since this is a student
project it means you cannot really expect 100%
functionality from this.

Railway Reservation System


Project in C++ With Source
Code
The C++ programming language  was used to make
the Railway Reservation System in C+ +. People
who use this small system can find out about train
schedules and make reservations.

A railway ticket reservation system project in C+


+ users must be created from the Admin mode for the
first time. You can reuse the same user after they’ve
been developed, and they’ll be saved in separate
files.

ABOUT PROJECT PROJECT DETAILS

Project Name : train ticket reservation system

Project Platform : C/C++

Programming Language Used: C++ Programming Language

Developer Name : itsourcecode.com


ABOUT PROJECT PROJECT DETAILS

IDE Tool (Recommended): Dev-C++ /Codeblocks

Project Type : Desktop Application

Database: Stores data in .DAT file

Railway Reservation System Project in C++ With Source Code Information

In this source code for railway reservation system


in C++, the operations related to both of these modes
are very similar. You can build a detail database, add
details, show details, perform user management
functions, and view passenger information in Admin
mode.

To add and display train inquiry and reservation


records, this railway reservation system project
in C++ with output has two modes, password
protection, and some basic file handling operations.
This railway ticket reservation system project in  C++
is finished and error-free, and I’ve presented the
source code in an easy to understand format.
What is a railway reservation
system?
The software that manages all of the railroad’s
reservations is known as the Railway Reservation
System. It is entirely built on the idea of booking rail
tickets to various locations.

Previously, processing the tickets one at a time was a


highly challenging task, so software that can handle
all Railway Reservation System was required.
The Railway Reservation System was created as a
result. The employee’s stress and workload were
completely remove with the launching of this
technology.

Additionally, the tourists’ decision to reserve a ticket


in advance wasted time. However, nowadays,
booking a ticket only takes 10 to 15 minutes,
regardless of where the passenger is.

What are the advantages of railway


reservation system?
The following table lists some benefits of making
reservations online: You may easily buy or cancel
tickets online from the convenience of your home or
place of business.
You can save the time that would have been spent
traveling to the railway reservation office and waiting
in line for your turn by making your reservation
online. This will also save you the effort of standing
in line.

These are the following features of the


system
 The admin login is password protected, and we have developed separate logins for the
passengers as well.
 The administrator of this project has the ability to add, edit, delete, and construct trains.
 Only once the admin has added the train can the passenger make a reservation.
 Passengers can choose the train of their choice by viewing the actual data of the available
trains.
 The admin is granted full control over adding, changing, and removing trains.
 To store the booking data, this project makes use of the file handling notion.
 One of the project’s key features is the ability to cancel a ticket.
 The login password can be changed by the administrator.

Working of Project
 You can manually run the complete project by
using the executable.exe file that is included in
the zip package. We’ll now see how the full
application functions along with an explanation.
On the main screen, we have displayed the menu with the options to View information, Book
the ticket, Cancel ticket, and Admin as well as Exit.
 View Information: When selecting this option, the user will be able to view all of the
information concerning the trains that are now accessible. All of the trains’ specifics, which are
now saved under the name “train details” in a file, will be displayed in this section.
 Cancel Ticket: If the passenger’s plans change and he decides that he needs to cancel the ticket
right away, the application provides the option to do so fast, should that be necessary.
 Admin: Because he is the only person who can manage the entire Train Booking System, the
Admin is sometimes referred to as the “heart” of the program or project. Only the admin has
access to read, write, update, and remove information, and we’ve given them everything to
them.
 View Passengers: When you select this item from the menu, all of the booking information for
the passengers, including the train number and seat number, will be presented.
 Add Train: The administrator will have the ability to add trains that are available for travel on a
particular day. During the process of adding the train, the program will inquire about each and
every detail that follows the train.
 Delete Train: If the admin wants to delete the train due to some issues, then the admin will be
able to instantly delete the train by choosing this option. Trian will be deleted only on the basis
of train number.
Top Best C Projects with Source Code for Beginners Free Download 2022 is a new essay I wrote
to improve your programming skills, especially C/C++.

To run this railway reservation system project in C++ ppt make sure that you have a Code
Blocks or any platform of C++ installed in your computer.

Railway Reservation System in C++ with


Source Code Steps On How To Run The
Project
Time needed: 5 minutes.

These are the steps on how to run  Railway


Reservation System in C++ with Source Code

Step 1: Download the Source Code,

First, You’ll need to download the source code that’s


provided below.

Step 2: Extract the file folder.


Second, after you finished download the source code,
extract the zip file.

Step 3: Open Code Blocks Application


Third, Open up your Code Blocks integrated
development environment (IDE) on your desktop.
Step 4: Open Project.
Fourth, open file tab and Open File after that open
folder RailwaySystem then click the
“railwayReservation.cpp“

Step 5: Run the Project System


Fifth, run the project system to show the output.

 Step 6: The actual code that makes up the


system’s program.
You are free to copy the given source code below
or download the downloadable source code
given.

Conclusion
The Railway Reservation System in C++ was created with the help of the C++ programming
language, and users of this little system can access both train schedules and reservation
information.

Users must first establish a railway ticket reservation system project in C++ from the Admin
mode. Once a user has been created, you can reuse them; their separate files will be saved.

Both of these modalities’ operations are handled similarly in this railway reservation system’s
C++ source code. In Admin mode, you can create a detail database, add details, show details,
manage users, and view passenger data.

Related Articles

 Library Management System In C++ With Source Code


 School Management System In C++ With Source Code

Inquiries
If you have any questions or suggestions about   railway
reservation system project in c++ pdf, please feel free to leave a comment below.
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string.h>
#include <time.h>
using namespace std;
char f[10] = "f";
char s[10] = "s";
int addr, ad, flag, f1, d, m, i, amt;
float tamt;
class login
{
public:
char id[100];
char pass[100];
char password[10];
void getid()
{
cout << "\nEnter your id:";
std::cin >> id;
std::cout << "Enter the Password: ";
std::cin >> password;
std::cout << "\n";
strcpy(pass,password);
}
void displayid()
{
std::cout << "\n|" << "User ID:" << "\t" << "|" << "Password\
n";
std::cout << "|" << id << "\t\t" << "|" << pass << "\n\n";
}
};
class Detail
{
public:
int tno;
char tname[100];
char bp[100];
char dest[100];

int c1,c1fare;
int c2,c2fare;
int d,m,y;
void getDetail()
{
std::cout << "\n--Add New details--\n";
std::cout << "Train no: ";
std::cin >> tno;
std::cout << "Train Name: ";
std::cin >> tname;
std::cout << "Boarding point: ";
std::cin >> bp;
std::cout << "Destination pt: ";
std::cin >> dest;
std::cout << "No of seats in first class & fare per
ticket: ";
std::cin >> c1 >> c1fare;
std::cout << "No of seats in second class & fare per
ticket: ";
std::cin >> c2 >> c2fare;
std::cout << "Date of travel\n";
std::cout << "Day: ";
std::cin >> d;
std::cout << "Month: ";
std::cin >> m;
std::cout << "Year: ";
std::cin >> y;
}
void displaydetail()
{
std::cout << "\n|Train No." << "\t" << "|Train Name" <<
"\t" << "|Boarding pt." << "\t" << "|Destination pt." <<"\t";
std::cout << "|F-Class" << "\t"<< "|F-Class Fare" <<
"\t" << "|S-Class" << "\t" << "|S-Class Fare" <<"\t";
std::cout << "|Day" << "-" << "Month" << "-" <<
"Year" << "\n";

std::cout << "|" << tno << "\t\t" << "|" << tname <<
"\t\t" << "|" << bp << "\t\t" << "|" << dest <<"\t\t\t";
std::cout << "|" << c1 << "\t\t" << "|"<< c1fare <<
"\t\t" << "|" << c2<< "\t\t" << "|" << c2fare <<"\t\t";
std::cout << "|" << d << "-" << m << "-" << y << "\
n";
}
};
class reser
{
public:
int pnr;
int tno;
char tname[100];
char bp[10];
char dest[100];
char pname[10][100];
int age[20];
char clas[10];
int nosr;
int i;
int d,m,y;
int con;

float amc;
void getresdet()
{
cout<<"Enter the details as follows\n";
cout<<"Train no:";
cin>>tno;
cout<<"Train name:";
cin>>tname;
cout<<"Boarding point:";
cin>>bp;
cout<<"Destination pt:";
cin>>dest;
cout<<"No of seats required:";
cin>>nosr;
for(i=0;i<nosr;i++)
{
cout<<"Passenger name:";
std::cin >> pname[i];
cout<<"Passenger age:";
std::cin>>age[i];
}
cout<<"Enter the class f-first class s-second class:";
std::cin >> clas;
cout<<"Date of travel:";
std::cin>>d>>m>>y;
cout<<"Enter the concession category\n";
cout<<"1.Military\n2.Senior citizen\n";
cout<<"3.Children below 5 yrs\n4.None\n";
std::cin>>con;
cout<<"…………END OF GETTING DETAILS…………\n";
}
void displayresdet()
{
cout<<"Pnr no: "<<pnr;
cout<<"\nTrain no: "<<tno;
cout<<"\nTrain name: "<<tname;
cout<<"\nBoarding point: "<<bp;
cout<<"\nDestination pt: "<<dest;
cout<<"\nNo of seats reserved: "<<nosr;
for(i=0;i<nosr;i++)
{
cout<<"\nPassenger name: ";puts(pname[i]);
cout<<"Passenger age: "<<age[i];
}

cout<<"\nYour class: ";puts(clas);


cout<<"\nDate of reservation: "<<d<<"-"<<m<<"-"<<y;
cout<<"\nYour concession category: "<<con;
cout<<"\nYou must pay: "<<amc<<endl;
cout<<"***********************************\n";
}
};
class canc
{
public:
int pnr;
int tno;
char tname[100];
char bp[10];
char dest[100];
char pname[10][100];
int age[20];
int i;
char clas[10];
int nosc;
int d, m, y;
float amr;
void getcancdet()
{
std::cout << "Enter the details as follows\n";
std::cout << "Pnr no:";
std::cin >> pnr;
std::cout << "Date of cancellation:";
std::cin >> d >> m >> y;
std::cout << "………..END OF GETTING DETAILS………..\n";
}
void displaycancdet()
{
std::cout << "…………………………………….\n";
std::cout << "…………………………………….\n";
std::cout << "Pnr no:" << pnr;
std::cout << "\nTrain no:" << tno;
std::cout << "\nTrain name:";
std::cout << tname;
std::cout << "Boarding point:";
std::cout << bp;
std::cout << "Destination pt:";
std::cout << dest;
cout << "\nYour class:";
std::cout << clas;
cout << "no of seats to be cancelled:" << nosc;
for (i = 0; i < nosc; i++)
{
std::cout << "Passenger name:";
std::cout << pname[i];
std::cout << "passenger age:" << age[i];
}
std::cout << "\nDate of cancellation:" << d << "-" << m << "-" <<
y;
std::cout << "\nYou can collect:" << amr << "rs" << endl;
std::cout << "*****************************************\n";
std::cout << "………END OF CANCELLATION………….\n";
std::cout << "*****************************************\n";
}
};
void manage();
void can();
void user();
void database();
void res();
void reserve();
void displaypassdetail();
void cancell();
void enquiry();
int main(void)
{
int ch;
std::cout << "----- RAILWAY RESERVATION SYSTEM ----- \n";
do
{
std::cout << "\n MAIN MENU \n";
std::cout << "1.Admin mode\n2.User mode\n3.Exit \n";
std::cout << "Enter your choice : ";
std::cin >> ch;
switch(ch)
{
case 1:
database();
break;
case 2:
user();
break;
default:
exit(0);
}
}while(ch<3);

return 0;
}

void database()
{
char password[10];
char pass[10] = "admin";
std::cout << "\nEnter the Admin Password: ";
std::cin >> password;
Detail a;
fstream f;
int ch;
char c;
if(strcmp(pass,password)!=0)
{
std::cout << "Enter the password correctly \n";
std::cout << "You are not permitted to login this mode\n";
}
if(strcmp(pass,password)==0)
{
char c;
do
{
std::cout << "\n --- ADMINISTRATOR MENU --- \n";
std::cout << "1. Create detail Database \n";
std::cout << "2. Add details \n";
std::cout << "3. Display details \n";
std::cout << "4. User Management \n";
std::cout << "5. Diplay Passenger details \n";
std::cout << "6. Return to Main Menu \n";
std::cout << "Enter your choice : ";
std::cin >> ch;
switch(ch)
{
case 1:
f.open("t.txt",ios::out|ios::binary);
do
{
a.getDetail();
f.write((char *) & a,sizeof(a));
cout << "\nDo you want to add one
more record?\n";
cout << "y-for Yes\nn-for No\n";
cin >> c;
}while(c=='y');
f.close();
break;
case 2:
f.open("t.txt",ios::in|ios::out|
ios::binary|ios::app);
a.getDetail();
f.write((char *) & a,sizeof(a));
f.close();
break;
case 3:
f.open("t.txt",ios::in|ios::out|
ios::binary|ios::app);
f.seekg(0);
while(f.read((char *) & a,sizeof(a)))
{
a.displaydetail();
}
f.close();
break;
case 4:
manage();
break;
case 5:
displaypassdetail();
break;
}
}while(ch<=5);
}
}

void reserve()
{
int ch;
do
{
std::cout << "1.Reserve\n2.Return to the main menu\n";
std::cout << "Enter your choice:";
std::cin >> ch;
std::cout << endl;
switch (ch)
{
case 1:
res();
break;
}
} while (ch == 1);
}

void res()
{
Detail a;
reser b;
fstream f1, f2;
time_t t;
f1.open("t.txt", ios::in | ios::out | ios::binary);
f2.open("p.txt", ios::in | ios::out | ios::binary | ios::app);
int ch;
b.getresdet();
while (f1.read((char *)&a, sizeof(a)))
{
if (a.tno == b.tno)
{
if (strcmp(b.clas, f) == 0)
{
if (a.c1 >= b.nosr)
{
amt = a.c1fare;
addr = f1.tellg();
ad = sizeof(a.c1);
f1.seekp(addr - (7 * ad));
a.c1 = a.c1 - b.nosr;
f1.write((char *)&a.c1, sizeof(a.c1));
if (b.con == 1)
{
cout << "Concession category:MILITARY PERSONNEL\
n";
b.amc = b.nosr * ((amt * 50) / 100);
}
else if (b.con == 2)
{
cout << "Concession category:SENIOR CITIZEN\n";
b.amc = b.nosr * ((amt * 60) / 100);
}
else if (b.con == 3)
{
cout << "Concession category:CHILDERN BELOW FIVE\
n";
b.amc = 0.0;
}
else if (b.con == 4)
{
cout << "You cannot get any concession\n";
b.amc = b.nosr * amt;
}
srand((unsigned)time(&t));
b.pnr = rand();
f2.write((char *)&b, sizeof(b));
b.displayresdet();
cout << "\n-----Your ticket is reserved-----\n";
}
else
{
cout << "**********Sorry req seats not
available********\n";
}
}
else if (strcmp(b.clas, s) == 0)
{
if (a.c2 >= b.nosr)
{
amt = a.c2fare;
addr = f1.tellg();
ad = sizeof(a.c2);
f1.seekp(addr - (5 * ad));
a.c2 = a.c2 - b.nosr;
f1.write((char *)&a.c2, sizeof(a.c2));
if (b.con == 1)
{
cout << "Concession category:MILITARY PRESONNEL\
n";
b.amc = b.nosr * ((amt * 50) / 100);
}
else if (b.con == 2)
{
cout << "Concession category:SENIOR CITIZEN\n";
b.amc = b.nosr * ((amt * 60) / 100);
}
else if (b.con == 3)
{
cout << "Concession category:CHILDERN BELOW FIVE\
n";
b.amc = 0.0;
}
else if (b.con == 4)
{
cout << "You cannot get any concession\n";
b.amc = b.nosr * amt;
}
f2.write((char *)&b, sizeof(b));
b.displayresdet();
cout << "\n-----Your ticket is reserved-----\n";
}
else
{
cout << "********Sorry req no of seats not
available*******\n";
}
}
}
else
{
flag = 0;
}
}
if (flag == 0)
{
cout << "!\n";
}
f1.close();
f2.close();
}

void displaypassdetail()
{
std::cout << "\n--------Passenger Details--------\n";
fstream f;
reser b;
f.open("p.txt",ios::in|ios::out|ios::binary);
f.seekg(0);
while(f.read((char *) & b,sizeof(b)))
{
b.displayresdet();
}
f.close();
}
void enquiry()
{
fstream f;
f.open("t.txt",ios::in|ios::out|ios::binary);
Detail a;
while(f.read((char *) & a,sizeof(a)))
{
a.displaydetail();
}
}
void cancell()
{
Detail a;
reser b;
canc c;
fstream f1, f2, f3;
f1.open("t.txt",ios::in|ios::out|ios::binary);
f2.open("p.txt",ios::in|ios::out|ios::binary);
f3.open("cn.txt",ios::in|ios::out|ios::binary);
cout<<"**********CANCELLATION MENU*********\n";
c.getcancdet();
while(f2.read((char *) & b,sizeof(b)))
{
if (b.pnr == c.pnr)
{
c.tno = b.tno;
strcpy(c.tname, b.tname);
strcpy(c.bp, b.bp);
strcpy(c.dest, b.dest);
c.nosc = b.nosr;
for (int j = 0; j < c.nosc; j++)
{
strcpy(c.pname[j], b.pname[j]);
c.age[j] = b.age[j];
}
strcpy(c.clas, b.clas);
if (strcmp(c.clas, f) == 0)
{
while (f1.read((char *)&a, sizeof(a)))
{
if (a.tno == c.tno)
{
a.c1 = a.c1 + c.nosc;
d = a.d;
m = a.m;
addr = f1.tellg();
ad = sizeof(a.c1);
f1.seekp(addr - (7 * ad));
f1.write((char *)&a.c1, sizeof(a.c1));
tamt = b.amc;
if ((c.d == d) && (c.m == m))
{
cout << "You are cancelling at the date of
departure\n";
c.amr = tamt - ((tamt * 60) / 100);
}
else if (c.m == m)
{
cout << "You are cancelling at the month of
departure\n";
c.amr = tamt - ((tamt * 50) / 100);
}
else if (m > c.m)
{
cout << "You are cancelling one month before
the date of departure\n";
c.amr = tamt - ((tamt * 20) / 100);
}
else
{
cout << "Cancelling after the departure\n";
cout << "Your request cannot be completed\n";
}
goto h;
c.displaycancdet();
}
}
}
else if (strcmp(c.clas, s) == 0)
{
while (f1.read((char *)&a, sizeof(a)))
{
if (a.tno == c.tno)
{
a.c2 = a.c2 + c.nosc;
d = a.d;
m = a.m;
addr = f1.tellg();
ad = sizeof(a.c2);
f1.seekp(addr - (5 * ad));
f1.write((char *)&a.c2, sizeof(a.c2));
tamt = b.amc;
if ((c.d == d) && (c.m == m))
{
cout << "You are cancelling at the date of
departure\n";
c.amr = tamt - ((tamt * 60) / 100);
}
else if (c.m == m)
{
cout << "You are cancelling at the month of
departure\n";
c.amr = tamt - ((tamt * 50) / 100);
}
else if (m > c.m)
{
cout << "You are cancelling one month before
the date of departure\n";
c.amr = tamt - ((tamt * 20) / 100);
}
else
{
cout << "Cancelling after the departure\n";
cout << "Your request cannot be completed\n";
}
goto h;
c.displaycancdet();
}
}
}
}
else
{
flag = 0;
}
}
h:
if(flag==0)
{
cout << "Enter the correct pnr no\n";
}
f1.close();
f2.close();
f3.close();
}
void can()
{
int ch;
do
{
cout << "……………..CANCELLATION MENU………\n";
cout << "1.Cancel\n2.Return to the main menu\n";
cout << "Enter your choice:";
cin >> ch;
cout << endl;
switch (ch)
{
case 1:
cancell();
break;
}
} while (ch == 1);
}
void user()
{
login a;
int ch;
cout<<"\n-----Login User-----\n";
char password[10];
fstream f;
f.open("id.txt",ios::in|ios::out|ios::binary);
char id[100];
std::cout << "Enter your ID : ";
std::cin >> id;
std::cout << "Enter your Password : ";
std::cin >> password;
while(f.read((char *) & a,sizeof(a)))
{
if((strcmp(a.id,id)==0)&&(strcmp(a.pass,password)==0))
{
do
{
std::cout<<"\n1.Reserve\n2.Cancel\n3.Enquiry\
n4.Return to the main menu\n";
cout<<"Enter your choice:";
cin>>ch;
switch(ch)
{
case 1:
reserve();
break;
case 2:
cancell();
break;
case 3:
enquiry();
break;
}
}while(ch<=3);
}
else
{
d=1;
}
}
if(d==1)
{
cout<<"Enter your user id and password correctly\n";
}
}

void manage()
{
int ch;
fstream f;
char c;
login a;
std::cout<<"\n---WELCOME TO THE USER MANAGEMENT MENU---\n";
do
{
std::cout << "1. Create id database\n";
std::cout << "2. Add details\n";
std::cout << "3. Display details\n";
std::cout << "4. Return to the main menu\n";
std::cout << "Enter your choice: ";
std::cin>>ch;
switch(ch)
{
case 1:
f.open("id.txt",ios::out|ios::binary);
do
{
a.getid();
f.write((char *) & a,sizeof(a));
std::cout << "Do you want to add one
more record\n";
std::cout << "y-Yes\nn-No\n";
std::cin>>c;
}while(c == 'y');
f.close();
break;
case 2:
f.open("id.txt",ios::in|ios::out|ios::binary|
ios::app);
a.getid();
f.write((char *) & a,sizeof(a));
f.close();
break;
case 3:
f.open("id.txt",ios::in|ios::out|
ios::binary);
f.seekg(0);
while(f.read((char *) & a,sizeof(a)))
{
a.displayid();
}
f.close();
break;
}
}while(ch<=3);
}

Railway Reservation System


Project in C++ With Source
Code
The C++ programming language  was used to make
the Railway Reservation System in C+ +. People
who use this small system can find out about train
schedules and make reservations.

A railway ticket reservation system project in C+


+ users must be created from the Admin mode for the
first time. You can reuse the same user after they’ve
been developed, and they’ll be saved in separate
files.

ABOUT PROJECT PROJECT DETAILS

Project Name : train ticket reservation syste


ABOUT PROJECT PROJECT DETAILS

Project Platform : C/C++

Programming Language Used: C++ Programming Language

Developer Name : itsourcecode.com

IDE Tool (Recommended): Dev-C++ /Codeblocks

Project Type : Desktop Application

Database: Stores data in .DAT file

Railway Reservation System Project in C++ With Source Code Information

In this source code for railway reservation system


in C++, the operations related to both of these modes
are very similar. You can build a detail database, add
details, show details, perform user management
functions, and view passenger information in Admin
mode.

To add and display train inquiry and reservation


records, this railway reservation system project
in C++ with output has two modes, password
protection, and some basic file handling operations.
This railway ticket reservation system project in  C++
is finished and error-free, and I’ve presented the
source code in an easy to understand format.

What is a railway reservation


system?
The software that manages all of the railroad’s
reservations is known as the Railway Reservation
System. It is entirely built on the idea of booking rail
tickets to various locations.

Previously, processing the tickets one at a time was a


highly challenging task, so software that can handle
all Railway Reservation System was required.
The Railway Reservation System was created as a
result. The employee’s stress and workload were
completely remove with the launching of this
technology.

Additionally, the tourists’ decision to reserve a ticket


in advance wasted time. However, nowadays,
booking a ticket only takes 10 to 15 minutes,
regardless of where the passenger is.

What are the advantages of railway


reservation system?
The following table lists some benefits of making
reservations online: You may easily buy or cancel
tickets online from the convenience of your home or
place of business.
You can save the time that would have been spent
traveling to the railway reservation office and waiting
in line for your turn by making your reservation
online. This will also save you the effort of standing
in line.

These are the following features of the


system
 The admin login is password protected, and we have developed separate logins for the
passengers as well.
 The administrator of this project has the ability to add, edit, delete, and construct trains.
 Only once the admin has added the train can the passenger make a reservation.
 Passengers can choose the train of their choice by viewing the actual data of the available
trains.
 The admin is granted full control over adding, changing, and removing trains.
 To store the booking data, this project makes use of the file handling notion.
 One of the project’s key features is the ability to cancel a ticket.
 The login password can be changed by the administrator.

Working of Project
 You can manually run the complete project by
using the executable.exe file that is included in
the zip package. We’ll now see how the full
application functions along with an explanation.
On the main screen, we have displayed the menu with the options to View information, Book
the ticket, Cancel ticket, and Admin as well as Exit.
 View Information: When selecting this option, the user will be able to view all of the
information concerning the trains that are now accessible. All of the trains’ specifics, which are
now saved under the name “train details” in a file, will be displayed in this section.
 Cancel Ticket: If the passenger’s plans change and he decides that he needs to cancel the ticket
right away, the application provides the option to do so fast, should that be necessary.
 Admin: Because he is the only person who can manage the entire Train Booking System, the
Admin is sometimes referred to as the “heart” of the program or project. Only the admin has
access to read, write, update, and remove information, and we’ve given them everything to
them.
 View Passengers: When you select this item from the menu, all of the booking information for
the passengers, including the train number and seat number, will be presented.
 Add Train: The administrator will have the ability to add trains that are available for travel on a
particular day. During the process of adding the train, the program will inquire about each and
every detail that follows the train.
 Delete Train: If the admin wants to delete the train due to some issues, then the admin will be
able to instantly delete the train by choosing this option. Trian will be deleted only on the basis
of train number.
Top Best C Projects with Source Code for Beginners Free Download 2022 is a new essay I wrote
to improve your programming skills, especially C/C++.

To run this railway reservation system project in C++ ppt make sure that you have a Code
Blocks or any platform of C++ installed in your computer.

Railway Reservation System in C++ with


Source Code Steps On How To Run The
Project
Time needed: 5 minutes.

These are the steps on how to run  Railway


Reservation System in C++ with Source Code

Step 1: Download the Source Code,


First, You’ll need to download the source code that’s
provided below.

Step 2: Extract the file folder.


Second, after you finished download the source code,
extract the zip file.

Step 3: Open Code Blocks Application


Third, Open up your Code Blocks integrated
development environment (IDE) on your desktop.

Step 4: Open Project.


Fourth, open file tab and Open File after that open
folder RailwaySystem then click the
“railwayReservation.cpp“

Step 5: Run the Project System


Fifth, run the project system to show the output.

 Step 6: The actual code that makes up the


system’s program.
You are free to copy the given source code below
or download the downloadable source code
given.

Conclusion
The Railway Reservation System in C++ was created with the help of the C++ programming
language, and users of this little system can access both train schedules and reservation
information.

Users must first establish a railway ticket reservation system project in C++ from the Admin
mode. Once a user has been created, you can reuse them; their separate files will be saved.

Both of these modalities’ operations are handled similarly in this railway reservation system’s
C++ source code. In Admin mode, you can create a detail database, add details, show details,
manage users, and view passenger data.

Related Articles
 Library Management System In C++ With Source Code
 School Management System In C++ With Source Code

Inquiries
If you have any questions or suggestions
about railway reservation system project in c++
pdf, please feel free to leave a comment below.

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string.h>
#include <time.h>
using namespace std;
char f[10] = "f";
char s[10] = "s";
int addr, ad, flag, f1, d, m, i, amt;
float tamt;
class login
{
public:
char id[100];
char pass[100];
char password[10];
void getid()
{
cout << "\nEnter your id:";
std::cin >> id;
std::cout << "Enter the Password: ";
std::cin >> password;
std::cout << "\n";
strcpy(pass,password);
}
void displayid()
{
std::cout << "\n|" << "User ID:" << "\t" << "|" << "Password\n";
std::cout << "|" << id << "\t\t" << "|" << pass << "\n\n";
}
};
class Detail
{
public:
int tno;
char tname[100];
char bp[100];
char dest[100];

int c1,c1fare;
int c2,c2fare;
int d,m,y;
void getDetail()
{
std::cout << "\n--Add New details--\n";
std::cout << "Train no: ";
std::cin >> tno;
std::cout << "Train Name: ";
std::cin >> tname;
std::cout << "Boarding point: ";
std::cin >> bp;
std::cout << "Destination pt: ";
std::cin >> dest;
std::cout << "No of seats in first class & fare per
ticket: ";
std::cin >> c1 >> c1fare;
std::cout << "No of seats in second class & fare per
ticket: ";
std::cin >> c2 >> c2fare;
std::cout << "Date of travel\n";
std::cout << "Day: ";
std::cin >> d;
std::cout << "Month: ";
std::cin >> m;
std::cout << "Year: ";
std::cin >> y;
}
void displaydetail()
{
std::cout << "\n|Train No." << "\t" << "|Train Name" << "\
t" << "|Boarding pt." << "\t" << "|Destination pt." <<"\t";
std::cout << "|F-Class" << "\t"<< "|F-Class Fare" << "\t"
<< "|S-Class" << "\t" << "|S-Class Fare" <<"\t";
std::cout << "|Day" << "-" << "Month" << "-" << "Year" <<
"\n";

std::cout << "|" << tno << "\t\t" << "|" << tname << "\t\
t" << "|" << bp << "\t\t" << "|" << dest <<"\t\t\t";
std::cout << "|" << c1 << "\t\t" << "|"<< c1fare << "\t\
t" << "|" << c2<< "\t\t" << "|" << c2fare <<"\t\t";
std::cout << "|" << d << "-" << m << "-" << y << "\n";
}
};
class reser
{
public:
int pnr;
int tno;
char tname[100];
char bp[10];
char dest[100];
char pname[10][100];
int age[20];
char clas[10];
int nosr;
int i;
int d,m,y;
int con;

float amc;
void getresdet()
{
cout<<"Enter the details as follows\n";
cout<<"Train no:";
cin>>tno;
cout<<"Train name:";
cin>>tname;
cout<<"Boarding point:";
cin>>bp;
cout<<"Destination pt:";
cin>>dest;
cout<<"No of seats required:";
cin>>nosr;
for(i=0;i<nosr;i++)
{
cout<<"Passenger name:";
std::cin >> pname[i];
cout<<"Passenger age:";
std::cin>>age[i];
}
cout<<"Enter the class f-first class s-second class:";
std::cin >> clas;
cout<<"Date of travel:";
std::cin>>d>>m>>y;
cout<<"Enter the concession category\n";
cout<<"1.Military\n2.Senior citizen\n";
cout<<"3.Children below 5 yrs\n4.None\n";
std::cin>>con;
cout<<"…………END OF GETTING DETAILS…………\n";
}
void displayresdet()
{
cout<<"Pnr no: "<<pnr;
cout<<"\nTrain no: "<<tno;
cout<<"\nTrain name: "<<tname;
cout<<"\nBoarding point: "<<bp;
cout<<"\nDestination pt: "<<dest;
cout<<"\nNo of seats reserved: "<<nosr;
for(i=0;i<nosr;i++)
{
cout<<"\nPassenger name: ";puts(pname[i]);
cout<<"Passenger age: "<<age[i];
}

cout<<"\nYour class: ";puts(clas);


cout<<"\nDate of reservation: "<<d<<"-"<<m<<"-"<<y;
cout<<"\nYour concession category: "<<con;
cout<<"\nYou must pay: "<<amc<<endl;
cout<<"***********************************\n";
}
};
class canc
{
public:
int pnr;
int tno;
char tname[100];
char bp[10];
char dest[100];
char pname[10][100];
int age[20];
int i;
char clas[10];
int nosc;
int d, m, y;
float amr;
void getcancdet()
{
std::cout << "Enter the details as follows\n";
std::cout << "Pnr no:";
std::cin >> pnr;
std::cout << "Date of cancellation:";
std::cin >> d >> m >> y;
std::cout << "………..END OF GETTING DETAILS………..\n";
}
void displaycancdet()
{
std::cout << "…………………………………….\n";
std::cout << "…………………………………….\n";
std::cout << "Pnr no:" << pnr;
std::cout << "\nTrain no:" << tno;
std::cout << "\nTrain name:";
std::cout << tname;
std::cout << "Boarding point:";
std::cout << bp;
std::cout << "Destination pt:";
std::cout << dest;
cout << "\nYour class:";
std::cout << clas;
cout << "no of seats to be cancelled:" << nosc;
for (i = 0; i < nosc; i++)
{
std::cout << "Passenger name:";
std::cout << pname[i];
std::cout << "passenger age:" << age[i];
}
std::cout << "\nDate of cancellation:" << d << "-" << m << "-" <<
y;
std::cout << "\nYou can collect:" << amr << "rs" << endl;
std::cout << "*****************************************\n";
std::cout << "………END OF CANCELLATION………….\n";
std::cout << "*****************************************\n";
}
};
void manage();
void can();
void user();
void database();
void res();
void reserve();
void displaypassdetail();
void cancell();
void enquiry();
int main(void)
{
int ch;
std::cout << "----- RAILWAY RESERVATION SYSTEM ----- \n";
do
{
std::cout << "\n MAIN MENU \n";
std::cout << "1.Admin mode\n2.User mode\n3.Exit \n";
std::cout << "Enter your choice : ";
std::cin >> ch;
switch(ch)
{
case 1:
database();
break;
case 2:
user();
break;
default:
exit(0);
}
}while(ch<3);

return 0;
}

void database()
{
char password[10];
char pass[10] = "admin";
std::cout << "\nEnter the Admin Password: ";
std::cin >> password;
Detail a;
fstream f;
int ch;
char c;
if(strcmp(pass,password)!=0)
{
std::cout << "Enter the password correctly \n";
std::cout << "You are not permitted to login this mode\n";
}
if(strcmp(pass,password)==0)
{
char c;
do
{
std::cout << "\n --- ADMINISTRATOR MENU --- \n";
std::cout << "1. Create detail Database \n";
std::cout << "2. Add details \n";
std::cout << "3. Display details \n";
std::cout << "4. User Management \n";
std::cout << "5. Diplay Passenger details \n";
std::cout << "6. Return to Main Menu \n";
std::cout << "Enter your choice : ";
std::cin >> ch;

switch(ch)
{
case 1:
f.open("t.txt",ios::out|ios::binary);
do
{
a.getDetail();
f.write((char *) & a,sizeof(a));
cout << "\nDo you want to add one more
record?\n";
cout << "y-for Yes\nn-for No\n";
cin >> c;
}while(c=='y');
f.close();
break;
case 2:
f.open("t.txt",ios::in|ios::out|ios::binary|
ios::app);
a.getDetail();
f.write((char *) & a,sizeof(a));
f.close();
break;
case 3:
f.open("t.txt",ios::in|ios::out|ios::binary|
ios::app);
f.seekg(0);
while(f.read((char *) & a,sizeof(a)))
{
a.displaydetail();
}
f.close();
break;
case 4:
manage();
break;
case 5:
displaypassdetail();
break;
}
}while(ch<=5);
}
}

void reserve()
{
int ch;
do
{
std::cout << "1.Reserve\n2.Return to the main menu\n";
std::cout << "Enter your choice:";
std::cin >> ch;
std::cout << endl;
switch (ch)
{
case 1:
res();
break;
}
} while (ch == 1);
}

void res()
{
Detail a;
reser b;
fstream f1, f2;
time_t t;
f1.open("t.txt", ios::in | ios::out | ios::binary);
f2.open("p.txt", ios::in | ios::out | ios::binary | ios::app);
int ch;
b.getresdet();
while (f1.read((char *)&a, sizeof(a)))
{
if (a.tno == b.tno)
{
if (strcmp(b.clas, f) == 0)
{
if (a.c1 >= b.nosr)
{
amt = a.c1fare;
addr = f1.tellg();
ad = sizeof(a.c1);
f1.seekp(addr - (7 * ad));
a.c1 = a.c1 - b.nosr;
f1.write((char *)&a.c1, sizeof(a.c1));
if (b.con == 1)
{
cout << "Concession category:MILITARY PERSONNEL\
n";
b.amc = b.nosr * ((amt * 50) / 100);
}
else if (b.con == 2)
{
cout << "Concession category:SENIOR CITIZEN\n";
b.amc = b.nosr * ((amt * 60) / 100);
}
else if (b.con == 3)
{
cout << "Concession category:CHILDERN BELOW FIVE\
n";
b.amc = 0.0;
}
else if (b.con == 4)
{
cout << "You cannot get any concession\n";
b.amc = b.nosr * amt;
}
srand((unsigned)time(&t));
b.pnr = rand();
f2.write((char *)&b, sizeof(b));
b.displayresdet();
cout << "\n-----Your ticket is reserved-----\n";
}
else
{
cout << "**********Sorry req seats not
available********\n";
}
}
else if (strcmp(b.clas, s) == 0)
{
if (a.c2 >= b.nosr)
{
amt = a.c2fare;
addr = f1.tellg();
ad = sizeof(a.c2);
f1.seekp(addr - (5 * ad));
a.c2 = a.c2 - b.nosr;
f1.write((char *)&a.c2, sizeof(a.c2));
if (b.con == 1)
{
cout << "Concession category:MILITARY PRESONNEL\
n";
b.amc = b.nosr * ((amt * 50) / 100);
}
else if (b.con == 2)
{
cout << "Concession category:SENIOR CITIZEN\n";
b.amc = b.nosr * ((amt * 60) / 100);
}
else if (b.con == 3)
{
cout << "Concession category:CHILDERN BELOW FIVE\
n";
b.amc = 0.0;
}
else if (b.con == 4)
{
cout << "You cannot get any concession\n";
b.amc = b.nosr * amt;
}
f2.write((char *)&b, sizeof(b));
b.displayresdet();
cout << "\n-----Your ticket is reserved-----\n";
}
else
{
cout << "********Sorry req no of seats not
available*******\n";
}
}
}
else
{
flag = 0;
}
}
if (flag == 0)
{
cout << "!\n";
}
f1.close();
f2.close();
}

void displaypassdetail()
{
std::cout << "\n--------Passenger Details--------\n";
fstream f;
reser b;
f.open("p.txt",ios::in|ios::out|ios::binary);
f.seekg(0);
while(f.read((char *) & b,sizeof(b)))
{
b.displayresdet();
}
f.close();
}
void enquiry()
{
fstream f;
f.open("t.txt",ios::in|ios::out|ios::binary);
Detail a;
while(f.read((char *) & a,sizeof(a)))
{
a.displaydetail();
}
}
void cancell()
{
Detail a;
reser b;
canc c;
fstream f1, f2, f3;
f1.open("t.txt",ios::in|ios::out|ios::binary);
f2.open("p.txt",ios::in|ios::out|ios::binary);
f3.open("cn.txt",ios::in|ios::out|ios::binary);
cout<<"**********CANCELLATION MENU*********\n";
c.getcancdet();
while(f2.read((char *) & b,sizeof(b)))
{
if (b.pnr == c.pnr)
{
c.tno = b.tno;
strcpy(c.tname, b.tname);
strcpy(c.bp, b.bp);
strcpy(c.dest, b.dest);
c.nosc = b.nosr;
for (int j = 0; j < c.nosc; j++)
{
strcpy(c.pname[j], b.pname[j]);
c.age[j] = b.age[j];
}
strcpy(c.clas, b.clas);
if (strcmp(c.clas, f) == 0)
{
while (f1.read((char *)&a, sizeof(a)))
{
if (a.tno == c.tno)
{
a.c1 = a.c1 + c.nosc;
d = a.d;
m = a.m;
addr = f1.tellg();
ad = sizeof(a.c1);
f1.seekp(addr - (7 * ad));
f1.write((char *)&a.c1, sizeof(a.c1));
tamt = b.amc;
if ((c.d == d) && (c.m == m))
{
cout << "You are cancelling at the date of
departure\n";
c.amr = tamt - ((tamt * 60) / 100);
}
else if (c.m == m)
{
cout << "You are cancelling at the month of
departure\n";
c.amr = tamt - ((tamt * 50) / 100);
}
else if (m > c.m)
{
cout << "You are cancelling one month before
the date of departure\n";
c.amr = tamt - ((tamt * 20) / 100);
}
else
{
cout << "Cancelling after the departure\n";
cout << "Your request cannot be completed\n";
}
goto h;
c.displaycancdet();
}
}
}
else if (strcmp(c.clas, s) == 0)
{
while (f1.read((char *)&a, sizeof(a)))
{
if (a.tno == c.tno)
{
a.c2 = a.c2 + c.nosc;
d = a.d;
m = a.m;
addr = f1.tellg();
ad = sizeof(a.c2);
f1.seekp(addr - (5 * ad));
f1.write((char *)&a.c2, sizeof(a.c2));
tamt = b.amc;
if ((c.d == d) && (c.m == m))
{
cout << "You are cancelling at the date of
departure\n";
c.amr = tamt - ((tamt * 60) / 100);
}
else if (c.m == m)
{
cout << "You are cancelling at the month of
departure\n";
c.amr = tamt - ((tamt * 50) / 100);
}
else if (m > c.m)
{
cout << "You are cancelling one month before
the date of departure\n";
c.amr = tamt - ((tamt * 20) / 100);
}
else
{
cout << "Cancelling after the departure\n";
cout << "Your request cannot be completed\n";
}
goto h;
c.displaycancdet();
}
}
}
}
else
{
flag = 0;
}
}
h:
if(flag==0)
{
cout << "Enter the correct pnr no\n";
}
f1.close();
f2.close();
f3.close();
}
void can()
{
int ch;
do
{
cout << "……………..CANCELLATION MENU………\n";
cout << "1.Cancel\n2.Return to the main menu\n";
cout << "Enter your choice:";
cin >> ch;
cout << endl;
switch (ch)
{
case 1:
cancell();
break;
}
} while (ch == 1);
}
void user()
{
login a;
int ch;
cout<<"\n-----Login User-----\n";
char password[10];
fstream f;
f.open("id.txt",ios::in|ios::out|ios::binary);
char id[100];
std::cout << "Enter your ID : ";
std::cin >> id;
std::cout << "Enter your Password : ";
std::cin >> password;
while(f.read((char *) & a,sizeof(a)))
{
if((strcmp(a.id,id)==0)&&(strcmp(a.pass,password)==0))
{
do
{
std::cout<<"\n1.Reserve\n2.Cancel\n3.Enquiry\
n4.Return to the main menu\n";
cout<<"Enter your choice:";
cin>>ch;
switch(ch)
{
case 1:
reserve();
break;
case 2:
cancell();
break;
case 3:
enquiry();
break;
}
}while(ch<=3);
}
else
{
d=1;
}
}
if(d==1)
{
cout<<"Enter your user id and password correctly\n";
}
}

void manage()
{
int ch;
fstream f;
char c;
login a;
std::cout<<"\n---WELCOME TO THE USER MANAGEMENT MENU---\n";
do
{
std::cout << "1. Create id database\n";
std::cout << "2. Add details\n";
std::cout << "3. Display details\n";
std::cout << "4. Return to the main menu\n";
std::cout << "Enter your choice: ";
std::cin>>ch;
switch(ch)
{
case 1:
f.open("id.txt",ios::out|ios::binary);
do
{
a.getid();
f.write((char *) & a,sizeof(a));
std::cout << "Do you want to add one more
record\n";
std::cout << "y-Yes\nn-No\n";
std::cin>>c;
}while(c == 'y');
f.close();
break;
case 2:
f.open("id.txt",ios::in|ios::out|ios::binary|
ios::app);
a.getid();
f.write((char *) & a,sizeof(a));
f.close();
break;
case 3:
f.open("id.txt",ios::in|ios::out|ios::binary);
f.seekg(0);
while(f.read((char *) & a,sizeof(a)))
{
a.displayid();
}
f.close();
break;
}
}while(ch<=3);
}

You might also like