K Arya
K Arya
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.
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.
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.");
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 " );
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.
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.
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.
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.");
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 " );
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.
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.
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
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];
}
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);
}
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.
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];
}
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);
}