Page

Railway Reservation System in C++

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream.h>
#include<time.h>
#include<iomanip.h>
#include<fstream.h>
#include<dos.h>
#include<graphics.h>
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;
void getid()
{
cout<<"Enter your id:";gets(id);
password=getpass("Enter the password:");
strcpy(pass,password);
}
void displayid()
{
cout<<"Id:";puts(id);
cout<<"Password:";puts(pass);
}};
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()
{
clrscr();
cleardevice();
cout<<"Enter the details as follows\n";
cout<<"Train no      :";cin>>tno;
cout<<"Train name    :";gets(tname);
cout<<"Boarding point:";gets(bp);
cout<<"Destination pt:";gets(dest);
cout<<"No of seats in first class & fare per ticket :";
cin>>c1>>c1fare;
cout<<"No of seats in second class & fare per ticket:";
cin>>c2>>c2fare;
cout<<"Date of travel:-(date,month,Year):";cin>>d>>m>>y;
}
void displaydetail()
{
setbkcolor(4);
cout<<tno<<"\t"<<tname<<"\t"<<bp<<"\t"<<dest<<"\t"; cout<<c1<<"\t"<<c1fare<<"\t"<<c2<<"\t"<<c2fare<<"\t"<<d<<"-"<<m<<"-"<<y<<"\t"<<endl;
}};

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()
{
clrscr();
cleardevice();
cout<<"Enter the details as follows\n";
cout<<"Train no            :";cin>>tno;
cout<<"Train name          :";gets(tname);
cout<<"Boarding point      :";gets(bp);
cout<<"Destination pt      :";gets(dest);
cout<<"No of seats required:";cin>>nosr;
for(i=0;i<nosr;i++)
{cout<<"Passenger name     :";gets(pname[i]);
cout<<"Passenger age       :";cin>>age[i]; }
cout<<"Enter the class f-first class s-second class:"; gets(clas);
cout<<"Date of travel      :";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";
cin>>con;
cout<<"............END OF GETTING DETAILS............\n";
}
void displayresdet()
{
clrscr();
cleardevice();
setbkcolor(4);
cout<<"                     Reservation Details                         \n";
cout<<".................................................................\n";
cout<<"Pnr no:"<<pnr;
cout<<"\nTrain no:"<<tno;
cout<<"\nTrain name:";puts(tname);
cout<<"Boarding point:";puts(bp);
cout<<"Destination pt:";puts(dest);
cout<<"No of seats reserved:"<<nosr;
for(i=0;i<nosr;i++)
{
cout<<"Passenger 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";
cout<<".........END OF RESERVATION.................\n";
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()
{
cout<<"Enter the details as follows\n";
cout<<"Pnr no:";cin>>pnr;
cout<<"Date of cancellation:";cin>>d>>m>>y;
cout<<"...........END OF GETTING DETAILS...........\n";
}
void displaycancdet()
{
clrscr();
 cleardevice();
 setbkcolor(4);
cout<<"...........................................\n";
cout<<"...........................................\n";
cout<<"Pnr no:"<<pnr;
cout<<"\nTrain no:"<<tno;
cout<<"\nTrain name:";puts(tname);
cout<<"Boarding point:";puts(bp);
cout<<"Destination pt:";puts(dest);
cout<<"\nYour class:";puts(clas);
cout<<"no of seats to be cancelled:"<<nosc;
for(i=0;i<nosc;i++)
{cout<<"Passenger name:";puts(pname[i]);
cout<<"passenger age:"<<age[i];
}
cout<<"\nDate of cancellation:"<<d<<"-"<<m<<"-"<<y;
cout<<"\nYou can collect:"<<amr<<"rs"<<endl;
cout<<"*****************************************\n";
cout<<".........END OF CANCELLATION.............\n";
cout<<"*****************************************\n";
}};

void manage();
void can();
void user();
void database();
void res();
void box();
void reserve();
void displaypassdetail();
void cancell();
void enquiry();
void rose();
void main()
{
int ch;
int gd=0,ram;
initgraph(&gd,&ram,"..\\bgi");
rose();

j:
box();
getch();
}
void box()
{
int li,lp,ch;
do
{
clrscr();
cleardevice();
setbkcolor(2);
setfillstyle(8,12);
bar(0,200,640,750);
for(li=30;li<=60;li++)
{
gotoxy(li,14);
delay(30);
printf("*");
}
for(li=30;li<=60;li++)
{
gotoxy(li,17);
delay(30);
printf("*");
}

for(li=60;li>=30;li--)
{
gotoxy(li,25);
delay(30);
printf("*");
}
for(lp=15;lp<25;lp++)
{
gotoxy(30,lp);
delay(50);
printf("|");
}
for(lp=25;lp>=15;lp--)
{
gotoxy(60,lp);
delay(50);
printf("|");
}
setfillstyle(1,4);
 bar(240,220,470,385);
gotoxy(2,25);
settextstyle(7,0,3);
setcolor(RED);
outtextxy(32,25,"WELCOME TO RAILWAY RESERVATION SYSTEM");
setcolor(4);
line(15,55,630,55);
setcolor(YELLOW);
line(15,52,630,52);
settextstyle(2,0,8);
setfillstyle(1,BLUE);
line(335,130,130,189);
bar(0,60,700,130);
setfillstyle(1,6);
bar(0,130,700,210);
setcolor(4);
outtextxy(150,60,"Created By:");
setcolor(15);
outtextxy(320,60,"Anupam Chamoli");
setcolor(4);
outtextxy(150,100,"Roll No   :");
setcolor(15);
outtextxy(320,100,"RD3002B31");
gotoxy(40,10);cout<<"             Contact              ";
gotoxy(40,11);cout<<"----------------------------------";
gotoxy(40,12);cout<<"BLOG: sourcecodernp.blogspot.com";
gotoxy(40,13);cout<<"        Mob.No: 8146866191        ";
gotoxy(5,10);cout<<"         Submitted To :";
gotoxy(5,11);cout<<"-----------------------";
gotoxy(5,12);cout<<"(Faculty Name)";
for(li=0;li<15;li++)
{setcolor(li);
 rectangle(li,li,640-li,480-li);
 }
setcolor(0);
outtextxy(260,230,"Main Menu");
gotoxy(25,40);
setcolor(15);
settextstyle(1,0,1);
outtextxy(250,270,"1 >> (Admin mode)");
gotoxy(25,45);
setcolor(13);
outtextxy(250,300,"2 >> (User mode)");
gotoxy(25,50);
setcolor(BLUE);
outtextxy(250,330,"3 >> (Exit)");
gotoxy(5,85);
setcolor(BLINK+YELLOW);
outtextxy(250,360,"Enter your choice....");
gotoxy(55,24);
cin>>ch;
cout<<endl;
switch(ch)
{
case 1: database();
break;
case 2:
user();
break;
case 3:
cleardevice();
settextstyle(3,0,8);
setbkcolor(1);
for(i=0;i<50;i++)
{         int z=4;
if(i/3==0)
z++;
setcolor(z);
outtextxy(100,100+i,"Thank You");
delay(100);
}
setcolor(15);
settextstyle(2,0,10);
outtextxy(10,250,"For using this software..!");
sleep(3);
exit(0);
}}while(ch<=3);

}



void database()
{
clrscr();
cleardevice();
setbkcolor(4);
char *password; char *pass="sourcecodernp",star[10];
int v=0;
star[6]=NULL;
//password=getpass("Enter the admininistrator password:");
printf("\n\n\n\n\n\n\t\tEnter the admin password:");
while(star[v]!=NULL)
{
star[v]=getch();
fflush(stdin);
printf("*");
v++;
}
//password=star;
printf("\n\t\t Please wait...");
delay(1000);
detail a;
fstream f;
int ch;
char c;
if(strcmp(pass,star)!=0)
{
delay(100);
cout<<"Enter the password correctly \n";
cout<<"You are not permitted to logon this mode\n";
getch();
goto h;
}if(strcmp(pass,star)==0)
{char c;
do
{
clrscr();
cleardevice();
setbkcolor(2);
setcolor(15);
line(210,120,540,120);
line(210,260,540,260);
rectangle(210,80,540,300);
setcolor(4);
outtextxy(270,90,"ADMINISTRATOR MENU");
setcolor(1);
outtextxy(220,130,"1 >> (Create detail data base)");
setcolor(14);
outtextxy(220,150,"2 >> (Add details)");
setcolor(3);
outtextxy(220,170,"3 >> (Display details)");
setcolor(4);
outtextxy(220,190,"4 >> (User management)");
setcolor(5);
outtextxy(220,210,"5 >> (Display passenger details)");
setcolor(6);
outtextxy(220,230,"6 >> (Return to main menu)");
setcolor(7);
outtextxy(220,270," (Enter your choice)..");
cin>>ch;
cout<<endl; switch(ch)
{case 1: f.open("t.txt",ios::out|ios::binary);
do
{
clrscr();
cleardevice();
a.getdetail();
f.write((char *) & a,sizeof(a));
cout<<"Do 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:
clrscr();
cleardevice();
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:
cleardevice();
setbkcolor(RED);
cout<<"                                 TRAIN DETAILS                                 "<<endl;
cout<<"--------------------------------------------------------------------------------"<<endl;
cout<<"T_no\tT_name\t   B_point\tD_point\tFC_seat\tFC_cost\tSC_seat\tSC_cost\tT_date\n";
cout<<"--------------------------------------------------------------------------------"<<endl;

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();
getch();
break;
case 4:
clrscr();
cleardevice();
manage();
break;
case 5:
clrscr();
cleardevice();
setbkcolor(9);
displaypassdetail();
getch();
break;
}
}while(ch<=5);
f.close(); }h:
}
void reserve()
{
clrscr();
cleardevice();
setbkcolor(13);
int ch;
do
{
clrscr();
cleardevice();
setbkcolor(12);
setcolor(1);
outtextxy(200,150,"1 >> Reserve");
outtextxy(200,180,"2 >> Return to the main menu");
outtextxy(200,210,"Enter your choice:");
cin>>ch;
cout<<endl;
switch(ch)
{
case 1:
res();
break;
}}while(ch==1);
getch();
}
void res()
{
clrscr();
cleardevice();
setcolor(0);
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";
cout<<"--------------Your ticket is reserved-----------\n";
cout<<"-----------------End of reservation menu-------\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";
cout<<"--------Your ticket is reserved--------\n";
cout<<"------------End of reservation---------\n";
}else
{cout<<"********Sorry req no of seats not available*******\n";
}}getch(); goto h; }else
{flag=0;
}}if(flag==0)
{cout<<"............Wrong train no......................\n";
cout<<"......Enter the train no from the data base.....\n"; }f1.close(); f2.close();
getch();
h:
}
void displaypassdetail()
{ clrscr();
cleardevice();
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(); getch();
}
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();
}getch();
}void cancell()
{
clrscr();
cleardevice();
setbkcolor(1);
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();
getch();
}
void can()
{
int ch; do {
clrscr();
cleardevice();
setbkcolor(3);
setcolor(14);
outtextxy(200,100,"CANCELLATION MENU");
setcolor(13);
outtextxy(150,150,"1 >> (Cancell)");
setcolor(12);
outtextxy(150,180,"2 >> (Return to the main menu)");
setcolor(11);
outtextxy(150,230,"(Enter your choice)");
cin>>ch;
cout<<endl;
switch(ch)
{case 1:
cancell();
break;
}}while(ch==1);
getch();
}
void user()
{
clrscr();
cleardevice();
login a; int ch;
char *password;
fstream f;
f.open("id.txt",ios::in|ios::out|ios::binary);
char id[100];
setcolor(15);
puts("\n\nEnter your id:");gets(id);
password=getpass("\nEnter your password:");
while(f.read((char *) & a,sizeof(a)))
{if((strcmp(a.id,id)==0)&&(strcmp(a.pass,password)==0))
{
do
{
clrscr();
cleardevice();
setbkcolor(BLUE);
setcolor(4);
settextstyle(2,0,5);
outtextxy(200,100,"WELCOME TO THE USER MENU");

rectangle(180,80,480,250);
setcolor(2);
outtextxy(200,120,"1 >> (Reserve)");
setcolor(3);
outtextxy(200,140,"2 >> (Cancell)");
setcolor(15);
outtextxy(200,160,"3 >> (Enquiry)");
setcolor(14);
outtextxy(200,180,"4 >> (Return to the main menu)");
setcolor(13);
textcolor(BLINK+YELLOW);
outtextxy(200,200,"(Enter your choice...)");
cin>>ch;
cout<<endl;
switch(ch)
{case 1:
reserve();
break;
case 2:
can();
break;
case 3:
clrscr();
cleardevice();
setbkcolor(8);
cout<<"                                 TRAIN DETAILS                                 "<<endl;
cout<<"--------------------------------------------------------------------------------\n";
cout<<"T_no\tT_name\t   B_point\tD_point\tFC_seat\tFC_cost\tSC_seat\tSC_cost\tT_date\n";
cout<<"--------------------------------------------------------------------------------"<<endl;

enquiry();
break;
}}while(ch<=3);
goto j; }else
{d=1;
}}if(d==1)
{cout<<"Enter your user id and password correctly\n"; }getch(); j: }


void manage()
{
int ch; fstream f;
char c;
login a;
do
{
clrscr();
cleardevice();
setcolor(4);
rectangle(90,90,530,260);
setbkcolor(6);
outtextxy(100,100,"WELCOME TO THE USER MANAGEMENT MENU");
setcolor(14);
outtextxy(150,130,"1 >> (Create id data base)");
setcolor(13);
outtextxy(150,150,"2 >> (Add details)");
setcolor(12);
outtextxy(150,170,"3 >> (Display details)");
setcolor(11);
outtextxy(150,190,"4 >> (Return to the main menu)");
setcolor(10);
outtextxy(150,230,"(Enter your choice)");
cin>>ch;
cout<<endl;
switch(ch)
{
case 1:
f.open("id.txt",ios::out|ios::binary);
do
{
a.getid();
f.write((char *) & a,sizeof(a));
cout<<"Do you want to add one more record\n";
cout<<"y-Yes\nn-No\n";
cin>>c;
}while(c=='y');
f.close();
break;
case 2:
clrscr();
cleardevice();
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:
clrscr();
cleardevice();
f.open("id.txt",ios::in|ios::out|ios::binary);
f.seekg(0);
while(f.read((char *) & a,sizeof(a)))
{
 a.displayid();
 }
 f.close();
 getch();
  break;
 }
 } while(ch<=3);
 getch();
 }
void rose()
 {
 int i,j,k=0,l=0,p=5,m=2,n=15,P;
clrscr();
cleardevice();
setbkcolor(0);
setcolor(YELLOW);
printf("\r\n\n\n\n\n\n\n\n\n\n\n\n\t\t\tInitializing....\n");
for(i=0;i<=300;i++)
{
P=i/3;
rectangle(200,250,200+i,230);
printf("\r\t\t\t\t\t\t\t    %d% Completed!",P);
delay(50);
}
cout<<"\n\n\n\n\n\n\n\n\n\n\t\t\t\Press any key to start..";
getch();
for(i=0;i<10;i++)
{
setfillstyle(i,4);
bar(i,780-i,780-i,i);
delay(30);
if(i==9)
sleep(1);
}
for(j=1;j<=21;j++,l++,m++)
{
settextstyle(1,0,5);
outtextxy(160,30," Welcome To");
outtextxy(2,300," Lovely Professional University");
for(i=0;i<15;i++,k++)
{
if(i==8)
setcolor(BLACK);
setcolor(i);
circle(335,180,i);
delay(2);
if(i==j)
k=0;
setcolor(RED+l);
ellipse(335,140,60,45,k,30);
delay(2);
ellipse(335,220,60,45,k,30);
delay(2);
ellipse(298,175,60,45,30,k);
delay(2);
ellipse(372,175,60,45,30,k);
delay(2);
}
for(i=j;i<n;i++)
{
setcolor(m);
ellipse(20,30,60,45,i,30+p);
delay(2);
ellipse(20,30,60,45,30+p,i);
}
for(i=j;i<n;i++)
{
setcolor(l);
ellipse(620,30,60,45,i,30+p);
delay(2);
ellipse(620,30,60,45,30+p,i);
}
for(i=j;i<n;i++)
{
setcolor(l+m);
ellipse(620,450,60,45,i,30+p);
delay(2);
ellipse(620,450,60,45,30+p,i);
}
for(i=j;i<n;i++)
{
setcolor(m+3);
ellipse(20,450,60,45,i,30+p);
delay(2);
ellipse(20,450,60,45,30+p,i);
}
n=n+5;
}
 }











No comments:

Post a Comment