Professional Documents
Culture Documents
PROGRAM LOGIC
The program declares a structure user which stores data members of
character and float type, which stores first name, last name, gender,
email address, password and residential address. And a structure
ticket which stores data members of character, double, float and
integer type, which stores the name of the passenger, departure
station address, destination address, departure date, total travelling
distance, total amount refunded, age and gender.
The program declares a main function signin(), signup(),options(),
booking(), checkpnr(), cancel(), showinfo(), dispinfo(), randomdist()
(for randomize), randompnr()(for randomize) , randomberth()(for
randomize).The main function contains 1 data member of integer type
to store the choice made by the user. The signup() function is used to
enter the first name, last name, gender, email address, password and
residential address of the user, all this information is stored in the
file account1.dat. In the signin() function the user is asked to enter
the login details i.e. the email id and password of the user. If the
login details given by the user matches the detais stored in the
database the function options() is called. In options() function the
user is asked to enter his/her choice, to book a train or to check pnr
status or to cancel reservation or to display customer details or to
exit and accordingly booking(), checkpnr(), cancel() and dispinfo()
functions are invoked,all this is done using switch case . In Booking()
function. In checkpnr() function the user is asked to enter the pnr
number allotted to him\her. And the pnr number is checked with the
pnr number in the database and if the number matches with the
number in the database the information of the passenger is displayed
Page | 2
Page | 3
PROGRAM CODE
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<fstream.h>
const float LOW=100;
const double LOW1=1000;
const int LOW2=1;
struct user
{
char fname[20];
char lname[20];
char gen[20];
char email[20];
char pass[20];
float ph;
char raddr[90];
};
user A;
struct ticket
{
char name[20],des[20],dep[20],date[10];
int age,pass,berth;
double pnr;
float trainno,fare,dist;
char gender[10];
}B;
void signin();
void signup();
void options();
void booking();
void checkpnr();
void cancel();
void showinfo();
void dispinfo();
int randomdist();
//for randomize
Page | 4
int randompnr();
//for randomize
int randomberth();
//for randomize
void main()
{
clrscr();
int choice;
cout<<" ENTER 1 to signin and 2 to signup \n::: ";
cin>>choice;
if(choice==1)
signin();
else if(choice==2)
signup();
getch();
}
void signin()
//for loging in
{
char mail[20],pas[20];
int ans,x=0;
fstream ob1;
ob1.open("account1.dat",ios::in);
cout<<":::: ENTER YOUR LOGIN DETAILS ::::\n";
cout<<"ENTER EMAIL ID: ";
gets(mail);
cout<<"ENTER PASSWORD: ";
gets(pas);
while(!ob1.eof())
{
if(!ob1.eof())
{
ob1.read((char*)&A,sizeof(A));
if(strcmp(mail,A.email)==0 && strcmp(pas,A.pass)==0)
{
if(x!=0)
break;
x++;
options();
}
}
}
if(x==0)
{
cout<<"E-mail account does not exist...";
cout<<"\n Press \n 1. to create a new account or \n2. to exit :";
cin>>ans;
if(ans==1)
{
Page | 5
signup();
}
}
ob1.close();
}
void signup()
//for creating account
{
fstream ob;
ob.open("account1.dat",ios::app);
cout<<":::: ENTER THE ITEMS ::::\n";
cout<<"Enter the first name :";
gets(A.fname);
cout<<"Enter the last name :";
gets(A.lname);
cout<<"Enter the gender
:";
gets(A.gen);
cout<<"Enter the email id :";
gets(A.email);
cout<<"Enter the password :";
cin>>A.pass;
cout<<"Enter the residential address:";
gets(A.raddr);
ob.write((char*)&A,sizeof(A));
ob.close();
cout<<"Account successfully created\n";
cout<<"Press any key to sign in...";
signin();
}
void options()
//for user choice
{
int choice;
char ans;
do
{
cout<<"Enter your choice: \n 1. Book train \n 2. Check pnr status \n 3. Cancel
reservation \n 4. Display customer details \n 5. Exit \n:::";
cin>>choice;
switch(choice)
{
case 1:
booking();
break;
case 2:
checkpnr();
break;
case 3:
Page | 6
cancel();
break;
case 4:
dispinfo();
break;
case 5:
exit(0);
default:
cout<<"WRONG CHOICE\n";
}
cout<<"\nDo you want to continue: ";
cin>>ans;
clrscr();
}while(ans=='y');
}
void booking()
//for booking ticket
{
clrscr();
int n,a,i,k;
float b,h,j,rpkm=5;
char e[20],f[20],g[10];
fstream ob;
ob.open("passenger.dat",ios::out);
cout<<"Enter the no. of passengers:";
cin>>n;
a=randompnr();
cout<<"===== PLEASE ENTER THE DETAIL CAREFULLY =====\n";
cout<<"Enter the train no.
: ";
cin>>b;
cout<<"Enter the departure station
: ";
gets(e);
cout<<"Enter the destination station
: ";
gets(f);
cout<<"Enter the departure date (dd/mm/yy) : ";
gets(g);
h=randomdist();
j=h*rpkm;
for(i=0;i<n;i++)
{
cout<<"\nDETAILS FOR PASSENGER ";
cout<<"\nEnter the name
: ";
gets(B.name);
cout<<"Enter the gender
: ";
gets(B.gender);
cout<<"Enter the age
: ";
cin>>B.age;
Page | 7
B.pnr=a+650000;
B.trainno=b;
strcpy(B.dep,e);
strcpy(B.des,f);
strcpy(B.date,g);
B.pass=n;
B.dist=h;
B.fare=j;
k=randomberth();
B.berth=k;
ob.write((char*)&B,sizeof(B));
}
showinfo();
}
void checkpnr()
{
double b;
int x=0;
ifstream ob;
ob.open("passeger.dat",ios::in);
cout<<"Enter te PNR to be searched:";
cin>>b;
while(!ob.eof())
{
ob.read((char*)&B,sizeof(B));
if(b==B.pnr && x==0)
{
x++;
showinfo();
}
else
{
cout<<"\n WRONG PNR";
}
}
ob.close();
}
void cancel()
//for cancelling ticket
{
double c;
ifstream ob;
ob.open("passeger.dat",ios::in);
ofstream ob1;
ob1.open("temp.dat",ios::in);
cout<<"Enter the PNR to be cancelled : ";
cin>>c;
Page | 8
while(!ob.eof())
{
int x=0;
ob.read((char*)&B,sizeof(B));
if(c==B.pnr && x==0)
{
cout<<"\nDETAILS OF THE CANCELLED RESERVATION:";
cout<<"\n PNR
: "<<B.pnr;
cout<<"\n Train No.
: "<<B.trainno;
cout<<"\n Departure
: "<<B.dep;
cout<<"\n Destination
: "<<B.des;
cout<<"\n Departure date
: "<<B.date;
cout<<"\n Total travelling distance : "<<B.dist<<"km";
cout<<"\n Total amount refunded
: Rs."<<B.fare-150;
cout<<"\n\n DETAILS FOR PASSENGER \n";
cout<<"\n Name
: "<<B.name;
cout<<"\n Gender
: "<<B.gender;
cout<<"\n Age
: "<<B.age;
x++;
break;
}
else
{
cout<<"\n WRONG PNR";
}
}
ob.close();
ob1.close();
remove("passenger.dat");
rename("temp.dat","passenger.dat");
}
int randomdist()
{
randomize();
float point=499,num=0;
for(int j=0;j<=1;j++)
{
num=LOW+random(point);
point--;
}
num=num;
return num;
}
int randompnr()
{
randomize();
Page | 9
double point=9999,num;
for(int j=0;j<=1;j++)
{
num=LOW+random(point);
point--;
}
return num;
}
int randomberth()
{
randomize();
float point=70,num=0;
for(int j=0;j<=1;j++)
{
num=LOW2+random(point);
point--;
}
num=num;
return num;
}
void showinfo()
//for displaying the ticket
{
int a,x=0;
a=randomdist();
ifstream ob;
ob.open("passenger.dat",ios::in);
cout<<"\n ============ YOUR BILLING DETAILS =========== \n";
while(!ob.eof())
{
ob.read((char*)&B,sizeof(B));
if(x==0)
{
cout<<"\n PNR
: "<<B.pnr;
cout<<"\n Train No.
: "<<B.trainno;
cout<<"\n Departure
: "<<B.dep;
cout<<"\n Destination
: "<<B.des;
cout<<"\n Departure date
: "<<B.date;
cout<<"\n Total travelling distance : "<<B.dist<<"km";
cout<<"\n Total fare
: Rs."<<B.fare;
cout<<"\n DETAILS FOR PASSENGER \n";
cout<<"\n Name
: "<<B.name;
cout<<"\n Gender
: "<<B.gender;
cout<<"\n Age
: "<<B.age;
cout<<"\n Berth allocated
: B2 "<<B.berth;
cout<<"\n--------------";
x++;
Page | 10
}
}
cout<<"\n===== THANK YOU AND HAVE A NICE JOURNEY =====\n";
ob.close();
}
void dispinfo()
//for displaying user information
{
char mail1[20],pas1[20];
int x=0;
fstream ob1;
ob1.open("account1.dat",ios::in);
cout<<":::: ENTER YOUR DETAILS ::::\n";
cout<<"ENTER EMAIL ID: ";
gets(mail1);
cout<<"ENTER PASSWORD: ";
gets(pas1);
while(!ob1.eof())
{
ob1.read((char*)&A,sizeof(A));
if(strcmp(mail1,A.email)==0 && strcmp(pas1,A.pass)==0 && x==0)
{
cout<<"\nFirst name
:"<<A.fname;
cout<<"\nLast name
:"<<A.lname;
cout<<"\nGender
:"<<A.gen;
cout<<"\nEmail id
:"<<A.email;
cout<<"\nPassword
:"<<A.pass;
cout<<"\nResidential address :"<<A.raddr;
x++;
}
}
}
Page | 11
OUTPUT SCREEN
Page | 12
Page | 13
VARIABLE
DESCRIPTION
VARIABL
E
DATATYPE
PURPOSE
fname
char
lname
char
gen
char
char
pass
char
ph
float
Page | 14
raddr
char
name
char
des
char
dep
char
date
char
age
int
berth
int
pnr
double
trainno
float
fare
float
dist
float
gender
char
LOW
int
LOW1
float
LOW2
float
char
pas
char
Page | 15
ans
char
rpkm
int
int
float
char
char
char
float
int
float
int
int
mail1
char
pas1
char
num
int
point
float
Page | 16
FUNCTION
NAME
DESCRIPTION
signin()
RETURN
TYPE
void
PURPOSE
To login into account
signup()
void
options()
void
booking()
void
To book a ticket
checkpnr()
void
cancel()
void
To cancel a ticket
showinfo()
void
dispinfo()
void
randomdist()
int
randompnr()
int
randomberth() int
Page | 18
BIBLOGRAPHY
These are the following links which assist me at each and
every step in completing this project , without them I
was not be able to finish this important project:1.www.scribd.com
2.www.wikipedia.com
3.www.answers.com
4.www.askme.com
5.www.google.com
Page | 19
Page | 20