This document contains source code for a C++ program that implements an online railway reservation system. It includes classes for login, train details, reservation, and cancellation. Functions are defined to manage the administrator database, user reservation and cancellation processes, and display output screens. The main function provides menus for admin and user modes. Admin can add, view, and manage train details while users can reserve and cancel tickets.
2. Done by
Name: r.sridhar
Roll no: 4611810
KENDRIYA VIDYALAYA No.2
THIRUPPARANKUNDRAM
BONAFIDE CERTIFICATE
This is to certify that this project entitled as “RAILWAY
RESERVATION” is a record of Bonafide work carried out
by R.SRIDHAR and in the fulfilment of all requirements in
computer as prescribed by CBSE AISSCE 2014-2015 for
class XII in school KENDRIYA VIDYALAYA
THIRUPARANKUNDRAM, MADURAI-625005.
3. Date:
internal examiner
Principal :
external examiner
ACKNOWLEDGEMENT
At the outset, I would like to express my humble thanks to the god almighty, for
the kind grace showed on us to complete the project successfully.
I would also like to express my sincere thanks to our Principal, Smt.GEETHA
KUMARI for rendering necessary facilities to our project.
4. I also convey our immense gratititude to our academic project guide Smt.
K.SHANMUGA PRIYA for her wonderful suggestions, Constant support, ideas
and extraordinary guidance throughout the project.
I would also like to convey our heartfelt thanks to all the staff members of my
school, my friends and my parents for extending their support and encouraged
me a lot to complete my project work on time.
6. C++ INTRODUCTION:
C++ IS A STATICALLY TYPED, FREE-FORM, MULTI-PARADIGM,
COMPILED, GENERAL PURPOSE PROGRAMMING LANGUAGE. IT IS
REGARED AS AN INTERMEDIATE-LEVEL LANGUAGE, AS IT
COMPRISES A COMBINATION OF BOTH HIGH LEVEL AND LOW
LEVEL LANGUAGE FEATURES. DEVELOPED BY BJARNE
STROUSTRUPSTARTING IN 1979 AT BELL LABS, IT ADDS OBJECT
ORIENTED FEATURES, SUCH AS CLASSES, AND OTHER
ENHANCEMENTS TO THE C PROGRAMMING LANGUAGE.
ORIGINALLY NAMED C WITH CLASSES, THE LANGUAGE WAS
RENAMED C++ IN 1983, AS A PUN INVOLVING THE INCREMENT
OPERATOR.
C++ IS ONE OF THE MOST POPULAR PROGRAMMING LANGUAGES
AND IS IMPLEMENTED ON A WIDE VARIETY OF HARDWARE AND
OPERATING SYSTEM PLATFORMS.AS AN EFFICIENT COMPILER TO
NATIVE CODE,ITS APPLICATION DOMAINS INCLUDE SYSTEMS
SOFTWARE, APPLICATION SOFTWARE,DEVICE DRIVERS,EMBEDDED
SOFTWARE,HIGH PERFORMANCE SERVER AND CLIENT
APPLICATIONS,AND ENTERTAINMENT SOFTWARE. SEVERAL
GROUPS PROVIDE BOTH FREE AND PROPRIETARY C++ COMPILER
SOFTWARE, INCLUDING THE GUN PROJECT, MICROSOFT, INTEL AND
EMBARCADERO TECHNOLOGIES.C++ HAS GREATLY INFLUENCED
MANY OTHER POPULAR PROGRAMMING LANGUAGES, MOST
NOTABLY C++AND JAVA.
C++ IS ALSO USED FOR HARDWARE DESIGN, WHERE THE DESIGN IS
INITIALLY DESCRBED IN C++, THEN ANALYZED,
ARCHITECTURALLY CONSTRAINED AND SCHEDULED TO CREATE A
REGISTER TRANSFER LEVEL HARDWARE DESCRIPTION LANGUAGE
VIA HIGH LEVEL SYNTHESIS.
7. OBJECTS:
C++ INTRODUCES OBJECT ORIENTED PROGRAMMIMG (00P)
FEATURES TO C. IT OFFERS CLASSES, WHICH PROVIDE THE FOUR
FERTURES COMMONLY PRESENT IN OOP LANGUAGES:
ABSTRACTION, ENCAPSULATION, INHERITANCE, AND
POLMORPHISM. ONE DISTINGUISHING FEATURE OF C++ CLASSES
COMPARED TO CLASSES IN OTHER PROGRAMMING LANGUAGES IS
SUPPORT FOR DETEMINISTIC DESTRUCTORS, WHICH IN TURN
PROVIDE SUPPORT FOR THE RESOURCE ACQUISITION IS
INITIALIZATION CONCEPT.
8. SYSTEM ENVIRONMENT:
3.1. HARDWARE CONFIGURATION:
PROCESSOR : INTEL i3@512GHz
MONITORS : 800*600 MINIUM RESOLUTIONS AT
256 COLORS MINIMUM
RAM : 2GB
HARD DISK : 250GB
KEYBOARD : TVS 140
MOUSE : LOGITECH
3.2. SOFTWARE CONFIGURATION:
LANGUAGE : C++ PROGRAMMING LANGUAGE
OPERATING SYSTEM : WINDOWS ‘XP’.
9. SYNOPSIS
RAILWAY RESERVATION IS BASIC AND SAMPLE OF
RESERVING TICKETS AND CANCELLATION OF RESERVED
TICKETS
DESCRIPTION:
THIS C++ PROGRAM ON RAILWAY RESERVATION IS A
SIMPLE TEXT BASE PROGRAM. WE HAVE USED PROCEDURE
ORIENTED METHOD TO DESIGN THIS PROGRAM. THIS
PROGRAM IS WITH GRAPHICS TO KEEP PROGRAM FOR
BEGINNERS. PASSENGERS HAS BEEN ASKED FOR ID AND
PASSWORD FOR PROTECTION .WE HAVE GIVEN USER
FRIENDLY MENUS TO ENQUIRE, RESERVE, CANCEL THE
RAILWAY TICKETS.
IN THIS PROJECT, WE HAVE USED PROGRAMMING CONCEPT
LIKE IF LOOP, USER DEFINED FUNCTION, LIBRARY
FUNCTION.
10. SOURCE CODE
//administrator password is ‘abc’
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<time.h>
#include<iomanip.h>
#include<fstream.h>
//Global variables
char f[2]="f"; //"f" for first-class
char s[2]="s"; //"s" for second-class
int addr,ad,flag=1,f1,d,m,i,amt; //amt -> amount
float tamt; //tamt -> total_amount
//First class : "login"
class login
{ public:
11. char id[20];
char pass[10]; //pass -> password
char *password;
void getid()
{ cout<<"Enter ID : "; gets(id);
password=getpass("Enter password : ");
strcpy(pass,password);
}
void displayid()
{
cout<<"User ID Information"<<endl<<endl;
cout<<"ID : ";puts(id);cout<<endl;
cout<<"Password : ";puts(pass);
}
};
//Second class : "detail" of train
class detail
{
public:
int tno; //tno -> Train Number
char tname[30]; //tname -> Train Name
char bp[20]; //bp -> Boarding Point
char dest[20]; //dest -> Destination
int c1,c1fare; //c1 -> First class c1fare -> First class fare
int c2,c2fare; //c2 -> Second class c2fare -> Second class fare
12. int d,m,y; //d -> date , m -> month , y -> year
void getdetail()
{
clrscr();
cout<<"Enter the details as follows"<<endl<<endl;
cout<<"Train number : ";cin>>tno;
cout<<"Train name : ";gets(tname);
cout<<"Boarding point : ";gets(bp);
cout<<"Destination point : ";gets(dest);
cout<<"No of seats in first class "<<endl;
cout<<"and fare per ticket : ";
cin>>c1>>c1fare;
cout<<"No of seats in second class "<<endl;
cout<<"and fare per ticket : ";
cin>>c2>>c2fare;
cout<<"Date of travel(in dd/mm/yy) : ";cin>>d>>m>>y;
}
void displaydetail()
{
cout<<"---------------------------------";
cout<<"-----------------------------------------------";
cout<<"Tr_No | Tr_Name | Start | Destin. |";
cout<<" FC_se | SC_se | Fr_FC | Fr_SC | Date of Jo.";
cout<<"n----------------------------------";
13. cout<<"----------------------------------------------n";
cout<<tno<<" "<<tname<<" "<<bp<<" "<<dest<<" "<<c1<<" "<<c2;
cout<<" "<<c1fare<<" "<<c2fare<<"
"<<d<<"/"<<m<<"/"<<y<<endl<<endl;
cout<<"----------------------------------";
cout<<"----------------------------------------------";
}
};
//Third class : "reser" for reservation
class reser : public detail
{
public:
int pnr; //pnr -> Passenger Name Record
int tno; //tno -> Train Number
char tname[30]; //tname -> Train Name
char bp[20];
char dest[20];
char pname[10][100];//pname -> Passenger Name
int age[20]; //age -> Age of passenger
char clas[10];
int nosr; //nosr -> No. of seats reserved
int i; //i -> Counter variable
int d,m,y;
14. int con; //con -> Concession amount
float amc; //amc -> Amount pay to customer
void getresdet();
void displayresdet();
};
void reser::getresdet() //getresdet -> get reservation details
{
clrscr();
cout<<"Enter the details as follows"<<endl<<endl;
cout<<"Train number : ";cin>>tno;
cout<<"Train name : ";gets(tname);
cout<<"Boarding point : ";gets(bp);
cout<<"Destination point : ";gets(dest);
cout<<"No of seats required : ";cin>>nosr;
for(i=0;i<nosr;i++)
{
cout<<"Passenger ("<<i+1<<") name : ";gets(pname[i]);
cout<<"Passenger ("<<i+1<<") age : ";cin>>age[i];
}
cout<<"Enter the class"<<endl;
cout<<"'f' for first class "<<endl;
cout<<"'s' for second class : ";gets(clas);
cout<<"Date of travel : ";cin>>d>>m>>y;
cout<<"nnEnter the concession category from belown";
15. cout<<"1.Militaryn2.Senior citizenn";
cout<<"3.Children(below 5 yrs)n4.Nonen";
cout<<"Enter your choice : ";cin>>con;
}
void reser::displayresdet() // Display reservation details
{
cout<<endl;
cout<<"-----------------------------------------------------n";
cout<<" RESERVATION STATUS n";
cout<<"-----------------------------------------------------n";
cout<<"PNR number : "<<pnr<<endl;
cout<<"Train number : "<<tno<<endl;
cout<<"Train name : ";puts(tname);
cout<<"Boarding point : ";puts(bp);
cout<<"Destination point : ";puts(dest);
cout<<"Number of seats reserved : "<<nosr<<endl;
for(i=0;i<nosr;i++)
{
cout<<"Passenger "<<i+1<<" name : ";puts(pname[i]);
cout<<"Passenger "<<i+1<<" age : "<<age[i]<<endl;
}
cout<<"Your class : ";puts(clas);
cout<<"Date of reservation : "<<d<<"/"<<m<<"/"<<y;
cout<<"nYour concession category : "<<con;
cout<<"nYou must pay : "<<amc<<endl;
16. cout<<"------------------------------------------------------n";
cout<<" END OF RESERVATION DETAILS OF PASSENGER n";
cout<<"------------------------------------------------------n";
}
//Fourth class : "canc" - cancellation of reserved ticket
class canc : public detail
{
public:
int pnr;
int tno;
char tname[100];
char bp[20];
char dest[20];
char pname[10][100];
int age[20];
int i;
char clas[10];
int nosc;
int d,m,y;
float amr;
void getcancdet()
{
cout<<"nnEnter the details as followsn";
17. cout<<"nPNR number : ";cin>>pnr;
cout<<"nDate of cancellation : ";cin>>d>>m>>y;
}
void displaycancdet();
};
void canc::displaycancdet()
{
cout<<"---------------------------------------------n";
cout<<" DISPLAY OF CANCELLATION n";
cout<<"---------------------------------------------n";
cout<<"PNR number : "<<pnr<<endl;
cout<<"Train number : "<<tno<<endl;
cout<<"Train name : ";puts(tname);
cout<<"Boarding point : ";puts(bp);
cout<<"Destination point : ";puts(dest);
cout<<"Your class : ";puts(clas);
cout<<"No of seats has been cancelled : "<<nosc<<endl;
for(i=0;i<nosc;i++)
{
cout<<"Passenger name : ";puts(pname[i]);
cout<<"Passenger age : "<<age[i]<<endl;
}
cout<<"Date of cancellation : "<<d<<"/"<<m<<"/"<<y<<endl;
cout<<"You can collect : Rs."<<amr<<endl;
cout<<"---------------------------------------------n";
18. cout<<" END OF CANCELLATION n";
cout<<"---------------------------------------------n";
}
//User-Defined Function(UDF) declaration part
void manage();
void can();
void user();
void database();
void res();
void reserve();
void displaypassdetail();
void cancell();
void enquiry();
//main function starts
void main()
{
int ch;
do
{
clrscr();
cout<<"-----------------------------------------------------------n";
19. cout<<" WELCOME TO ONLINE RAILWAY RESERVATION SYSTEM
n";
cout<<"-----------------------------------------------------------n";
cout<<"nn-----------------------------------------------------------n";
cout<<" MAIN MENU n";
cout<<"-----------------------------------------------------------n";
cout<<"nn1. Admin mode nn2. User mode nn3. Exitn";
cout<<"nEnter your choice : ";
cin>>ch;
cout<<endl;
switch(ch)
{
case 1:
database();
break;
case 2:
user();
break;
case 3:
exit(0);
}
}while(ch<=3);
getch();
20. }
//User-Defined Function(UDF) definition
void database() //Database function for administrator
{
char *password;
char *pass="abc";
password=getpass("nEnter the admininistrator password : ");
detail a;
fstream f;
int ch;
char c;
if(strcmp(pass,password)!=0)
{
cout<<"nEnter the password correctlyn";
cout<<"You are not permitted to login this moden";
getch();
goto h;
}
if(strcmp(pass,password)==0)
{
char c;
do
{
21. clrscr();
cout<<"n-----------------------------------------------------n";
cout<<" ADMINISTRATOR MENU n";
cout<<"-----------------------------------------------------n";
cout<<"nn1. Add detailsn";
cout<<"n2. Display detailsnn3. User managementn";
cout<<"n4. Display passenger detailsnn5. Return to main menun";
cout<<"nEnter your choice : ";
cin>>ch;
cout<<endl;
switch(ch)
{
case 1:
f.open("t.txt",ios::in|ios::out|ios::binary|ios::app);
do
{
a.getdetail();
f.write((char *) & a,sizeof(a));
cout<<"nnDo you want to add one more record?n";
cout<<"y-for Yesnn-for Non";
cout<<"Your answer : ";
cin>>c;
}while(c=='y');
f.close();
break;
32. c.amr=tamt-((tamt*20)/100);
}
else
{
cout<<"You are cancelling after the departure."<<endl;
cout<<"Your request cannot be completed."<<endl;
}
fstream fp2;
fp2.open("Temp.dat",ios::out);
f2.seekg(0,ios::beg);
while(f2.read((char*)&b,sizeof(b)))
{
if(b.pnr!=c.pnr)
{
fp2.write((char*)&b,sizeof(b));
}
}
fp2.close();
remove("p.txt");
rename("Temp.dat","p.txt");
c.displaycancdet();
goto h;
}
}
}
33. 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."<<endl;
c.amr=tamt-((tamt*60)/100);
}
else if((c.m==m) && (c.d<d))
{
cout<<"You are cancelling at the month of departure."<<endl;
c.amr=tamt-((tamt*50)/100);
}
else if(m>c.m)
34. {
cout<<"You are cancelling "<<m-c.m<<" month before the date of
departure."<<endl;
c.amr=tamt-((tamt*20)/100);
}
else
{
cout<<"You are cancelling after the departure."<<endl;
cout<<"Your request cannot be completed."<<endl;
}
fstream fp2;
fp2.open("Temp.dat",ios::out);
f2.seekg(0,ios::beg);
while(f2.read((char*)&b,sizeof(b)))
{
if(b.pnr!=c.pnr)
{
fp2.write((char*)&b,sizeof(b));
}
}
fp2.close();
remove("p.txt");
rename("Temp.dat","p.txt");
c.displaycancdet();
goto h;
36. clrscr();
cout<<"n----------------------------------------------------n";
cout<<" CANCELLATION MENU n";
cout<<"----------------------------------------------------n";
cout<<"nn1. Cancelnn2. Return to the main menun";
cout<<"nEnter your choice:";
cin>>ch;
cout<<endl;
switch(ch)
{
case 1:
cancell();
break;
}
}while(ch==1);
getch();
}
void user()
{
login a;
int ch;
clrscr();
cout<<"n-----------------------------------------------------n";
cout<<" USER MENU n";
39. {int ch;
fstream f;
char c;
login a;
clrscr();
cout<<"---------------------------------------------------------n";
cout<<" WELCOME TO THE USER MANAGEMENT MENU n";
cout<<"---------------------------------------------------------n";
do
{
cout<<"nn1. Add ID details of user n";
cout<<"n2. Display details of IDnn3. Return to the main menun";
cout<<"nEnter your choice : ";
cin>>ch;
cout<<endl;
switch(ch)
{
case 1:
f.open("id.txt",ios::in|ios::out|ios::binary|ios::app);
do
{
a.getid();
f.write((char *) & a,sizeof(a));
cout<<"nnDo you want to add one more record>?n";
45. CONCLUSION
THIS PROJECT MEETS THE REQUIREMENTS
SPECIFICATION. IT GIVES LOGICAL SOLUTION FOR
LONG TIME PROBLEM ON RESERVING TRAIN TICKETS
AND CANCELLATION OF TICKETS BOOKED.
AND FINALLY IT SUCCESSFULLY RUNS AND REPORTS
ARE GENERATED IN A NEAT MANNER. AS AIMED IT
REDUCES LOT OF PAPER REFERENCE AND USER
FRIENDLY.
THE PROGRAMMING TECHNIQUE USED IN THE DESIGN
OF THE SYSTEM PROVIDES A SCOPE FOR FURTHER
EXPANSION AND IMPLEMENTATION OF ANY
CHANGES, WHICH MAY OCCUR IN FUTURE.