0% found this document useful (0 votes)
333 views

indian Railways //developed by Georgy Jacob & Georgi Joseph Boby

This code defines classes for stations, trains, and railways to model an Indian railway system. It allows users to add new stations and trains, display existing stations, search for and reserve tickets between stations. Key functions include entering station and train data to text files, searching station data to calculate fares, and generating ticket bills. Header files are included for input/output streams and screen clearing. The main menu drives the user interface, calling functions from the station, train, and railway classes to perform allowed actions.

Uploaded by

Georgi Boby
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
333 views

indian Railways //developed by Georgy Jacob & Georgi Joseph Boby

This code defines classes for stations, trains, and railways to model an Indian railway system. It allows users to add new stations and trains, display existing stations, search for and reserve tickets between stations. Key functions include entering station and train data to text files, searching station data to calculate fares, and generating ticket bills. Header files are included for input/output streams and screen clearing. The main menu drives the user interface, calling functions from the station, train, and railway classes to perform allowed actions.

Uploaded by

Georgi Boby
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

CODE

//INDIAN RAILWAYS
//DEVELOPED by GEORGY JACOB & GEORGI JOSEPH BOBY
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<math.h>
#include<process.h>
#include<stdio.h>
int p=1;
class station
{public:
char name[15];
int x;
int y;
void display();
void enterdata();
}tr;
void station::enterdata()
{cout<<"ENTER THE NAME OF THE NEW STATION - "<<"\n";
cin>>tr.name;
cout<<"ENTER THE X COORDINATE - "<<"\n";
cin>>tr.x;
cout<<"ENTER THE Y COORDINATE - "<<"\n";
cin>>tr.y;
ofstream ob1;
ob1.open("station2.txt",ios::app|ios::binary);
ob1.write((char*)&tr,sizeof(tr));
ob1.close();

cout<<"DO YOU HAVE ANY MORE QUERIES(Y/N)?";


}; void station::display()
{ clrscr();
cout<<"THE LIST OF STATIONS ENETRED ARE (NAME-X-Y) \n";
ifstream po;
po.open("station2.txt",ios::app,ios::binary);
po.seekg(0);
while(!po.eof())
{ po.read((char*)&tr,sizeof(tr));
cout<<tr.name<<" - "<<tr.x<<" - "<<tr.y<<"\n";
};
po.close();
cout<<"DO YOU HAVE ANY MORE QUERIES? \n \n";
}
class train
{public:
char name7[25];
int y;
char s1[15],s2[15],s3[15],s4[15],s5[15],s6[15];
void entertrain();

}tr1;
void train::entertrain()
{ofstream od;
od.open("train.txt",ios::app,ios::binary);
cout<<"ENTER THE TRAIN NAME -";
cin>>tr1.name7;
cout<<"\n \nENTER THE TRAIN NUMBER -";
cin>>tr1.y;
cout<<" \n \nENTER THE STARTING STATION - ";
cin>>tr1.s1;

cout<<"\n \n ENTER THE NEXT STATION - ";


cin>>tr1.s2;
char g='Y';
int n=3;
while((n<7)&&(g=='Y'))
{cout<<" \n \n DOES TRAIN HAVE MORE STATIONS? \n ";
cin>>g;
if(g=='N')
{cout<<"ENTER NULL FOR ALL THE NEXT STATIONS";
g='Y';
};
if(g=='Y')
{ cout<<"\n \n ENTER THE NEXT STATION - ";
if(n==3)
cin>>tr1.s3;
if(n==4)
cin>>tr1.s4;
if(n==5)
cin>>tr1.s5;
if(n==6)
cin>>tr1.s6;
n++;
}
}
od.write((char*)&tr1,sizeof(tr1));
od.close();
cout<<"THANKYOU FOR USING OUR SERVICES \n" ;
cout<<"\n DO YOU HAVE ANY MORE QUERIES(Y/N)";
}
class railway
{public:
char start[15],end[15];

float startx,starty,endx,endy;
void search();

void calcfare();
float fare;
railway()
{fare=10;
}
}rail;
void railway::search()
{int y=0;
cout<<"ENTER THE BOARDING STATION - ";
cin>>rail.start;
cout<<"\nENTER THE TERMINAL STATION - ";
cin>>rail.end;
ifstream lop;
lop.open("station2.txt",ios::app,ios::binary);
while(!lop.eof())
{lop.read((char*)&tr,sizeof(tr));
if(!strcmp(rail.start,tr.name))
{rail.startx=tr.x;
rail.starty=tr.y;
y=y+1;
};
if(!strcmp(rail.end,tr.name))
{rail.endy=tr.y;
rail.endx=tr.x;
}
y=y+1;
}
lop.close();

if(y==0)
cout<<"\n \n STATION NOT FOUND \n \n DO YOU HAVE ANY MORE
QUERIES? \n";

};
void railway::calcfare()
{ int c;
c=rail.fare;
int x1,x2,y1,y2,y,f,y3,y4;
x1=(rail.startx);
x2=(rail.endx);
y1=(rail.starty);
y2=(rail.endy);
if(x2>x1)
y3=x2-x1;
if(x1>x2)
y3=x1-x2;
if(y1>y2)
y4=y1-y2;
if(y1<y2)
y4=y2-y1;
y=(y3*y3+y4*y4);
float z;
z=(sqrt(y));
ifstream we;
we.seekg(0);
we.open("train.txt",ios::app|ios::binary);
cout<<" \n AVILABLE TRAINS ARE : \n \n";
while(!we.eof())
{ int r=0,e=0;
we.read((char*)&tr1,sizeof(tr1));
if(!(strcmp(tr1.s1,rail.start)))

e++;
if(!(strcmp(tr1.s2,rail.start)))
e++;
if(!strcmp(tr1.s3,rail.start))
e++;
if(!strcmp(tr1.s4,rail.start))
e++;
if(!strcmp(tr1.s5,rail.start))
e++;
if(!strcmp(tr1.s6,rail.start))
e++;

if(!strcmp(tr1.s1,rail.end))
r++;
if(!strcmp(tr1.s2,rail.end) )
r++;
if(!strcmp(tr1.s3,rail.end))
r++;
if(!strcmp(tr1.s4,rail.end))
r++;
if(!strcmp(tr1.s5,rail.end))
r++;
if(!strcmp(tr1.s6,rail.end))
r++;
if((r==1)&&(e==1))
{
cout<<" "<<"->"<<" ["<<(tr1.y)<<"]
p++;
}
};
cout<<" \nTHE TOTAL FARE ="<<z*c<<"\n";

"<<(tr1.name7)<<"\n";

cout<<"\nDO YOU WANT TO ACCEPT THE TRANSACTION(Y/N) - ";


char s;
cin>>s;
if(s=='Y')
{
clrscr();
cout<<"\n TRANSACTION ACCEPTED \n";
clrscr();
cout<<"\n BILL: \n";
cout<<"----------------------------------------------------------------------------------";
cout<<"

INDIAN RAILWAYS E TICKET

\n \n";

cout<<"FROM : "<<rail.start<<"
"<<rail.end<<"\n";

"<<"TO :

cout<<"\n"<<"FARE = "<<z*c<<"\n \n \n";


cout<<"----------------------------------------------------------------------------------";
cout<<"THANKYOU FOR USING OUR SERVICES \n" ;
cout<<"\n DO YOU HAVE ANY MORE QUERIES(Y/N)";
}
}

void main()
{
char a='Y';
while(a=='Y')
{clrscr();

cout<<"
\n \n";

WELCOME TO INDIAN RAILWAYS

cout<<"

DEVELOPED BY:

cout<<"

GEORGY JACOB

cout<<"
getch();

GEORGI JOSEPH BOBY

\n \n
\n\n";
\n";

";

clrscr();
cout<<"

INDIAN RAILWAYS \n \n\n";

cout<<" ENTER CHOICE

\n";

cout<<"

1.ADD NEW STATION

\n";

cout<<"

2.RESERVE TICKET

\n";

cout<<"

3.DISPLAY STATIONS

\n";

cout<<"

4.ADD TRAIN

\n";

cout<<"

5.EXIT

\n";

cout<<"

\n";

cout<<"

\n";

int n;
cin>>n;
if(n==1)
{clrscr();
tr.enterdata();

cin>>a;
};
if(n==2)
{clrscr();
rail.search();
rail.calcfare();
cin>>a;
} ;
if(n==3)
{clrscr();
tr.display();
cin>>a;
};
if(n==4)
{clrscr();

tr1.entertrain();
cin>>a;
};
if(n==5)
{clrscr();
exit(0);
};

};}

INTRODUCTION

ENTERING NEW STATION

RESERVING TICKET

ENTERING NEW TRAIN

HEADER FILES USED


IOSTREAM.H-for cin and cout
CONIO.H-for getch(),clrscr()
PROCESS.H-for exit()
STDIO.H-for gets()

MATH.H-for pow()

FILES GENERATED
TRAIN.TXT
STATION2.TXT
CLASSES USED
STATION
RAILWAY
TRAIN

You might also like