Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<fstream>
- #include<conio.h>
- #include<stdio.h>
- #include<math.h>
- #include<string.h>
- #include<process.h>
- #include<iostream>
- #include<stdlib.h>
- using namespace std;
- void clrscr() //Implementing clrscr() in C++ GNU GCC COMPILER
- {
- system("cls");
- }
- class train
- {
- public:
- int tno;
- char tname[100];
- char source[100];
- char dest[100];
- int PerSeatFare;
- public:
- void getdetail()
- {
- cout<<"Enter the details as follows\n";
- cout<<"Train no:";
- cin>>tno;
- cin.ignore();
- cout<<"Train name:";
- gets(tname);
- cout<<"Train Source Station:";
- gets(source);
- cout<<"Tarin Destination Station:";
- gets(dest);
- cout<<"Fare per seat in train :";
- cin>>PerSeatFare;
- }
- void showdetail()
- {
- cout<<tno<<"\t"<<tname<<"\t"<<source<<"\t"<<dest<<"\t";
- cout<<PerSeatFare;
- }
- }t;
- void storetrain()
- {
- fstream f;
- train t;
- f.open("trains.dat",ios::app | ios::binary);
- t.getdetail();
- f.write((char*)&t,sizeof(t));
- f.close();
- }
- void showalltrain()
- {
- fstream f;
- f.open("trains.dat",ios::in | ios::binary);
- train t;
- while(f.read((char*)&t,sizeof(t)))
- {
- t.showdetail();
- cout<<endl;
- }
- getch();
- f.close();
- }
- class reserv //Assume that cust select train according to his source and destination.
- {
- public:
- int pnr;
- int tno;
- char tname[100];
- char pnames[10][100];
- int ages[10];
- int SeatNum;
- int i;
- int d,m,y;
- float amt;
- char bp[100],dest[100];
- void updt_tick()
- {
- fstream f;
- f.open("train.dat",ios::in | ios::binary);
- while(f.read((char*)&t,sizeof(t)))
- {
- if (tno==t.tno)
- {
- strcpy(bp,t.source);
- strcpy(dest,t.dest);
- strcpy(tname,t.tname);
- amt=SeatNum*t.PerSeatFare;
- break;
- }
- }
- f.close();
- }
- public:
- void getresdet()
- {
- cout<<"Enter the details as follows\n";
- cout<<"Train no:";
- cin>>tno;
- cout<<"No of seats required:";
- cin>>SeatNum;
- cin.ignore();
- for(i=0; i<SeatNum ; i++)
- {
- cout<<"Passenger name:";
- gets(pnames[i]);
- cout<<"Passenger age:";
- cin>>ages[i];
- cin.ignore();
- }
- cout<<"Date of travel:";
- cin>>d>>m>>y;
- cout<<"Details Accepted\n";
- pnr=rand();
- updt_tick();
- }
- void showresdet()
- {
- 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:"<<SeatNum;
- for(i=0; i<SeatNum; i++)
- {
- cout<<"Passenger name:";
- puts(pnames[i]);
- cout<<"Passenger age:"<<ages[i];
- }
- cout<<"\nDate of reservation:"<<d<<"-"<<m<<"-"<<y;
- cout<<"\nYou must pay:"<<amt<<endl;
- }
- int getpnr()
- {
- return pnr;
- }
- };
- void showticketbypnr()
- {
- fstream f;
- reserv r;
- int flag=0,pnr;
- cout<<"\nPlease enter your PNR :";
- cin>>pnr;
- f.open("reservations.dat",ios::in | ios::binary);
- while(f.read((char*)&r,sizeof(r)))
- {
- if(pnr==r.getpnr())
- {
- cout<<"Your details are as follows :\n";
- r.showresdet();
- flag=1;
- break;
- }
- }
- if(flag==0)
- {
- cout<<"This PNR was not found in our database !";
- }
- f.close();
- getch();
- }
- void bookticket()
- {
- reserv r;
- fstream f;
- f.open("reservations.dat",ios::app | ios::in | ios::binary);
- r.getresdet();
- f.write((char*)&r,sizeof(r));
- cout<<"Ticket is Booked";
- cout<<"Your details are as follows :\n";
- r.showresdet();
- getch();
- f.close();
- }
- void menu()
- {
- int opt,opt1,opt2;
- while(1){
- clrscr();
- cout<<"1.)Administrator Menu\n2.)Passenger Menu\n3.)Exit\n\nEnter your choice :";
- cin>>opt;
- if(opt==3)
- exit(0);
- else if(opt==1)
- {
- clrscr();
- cout<<"1.)Add new train to database\n2.)Show all trains in database\n3.)Modify a train information\n4.)Exit\n\nEnter your choice :";
- cin>>opt1;
- switch(opt1)
- {
- case 1:storetrain();
- break;
- case 2:showalltrain();
- break;
- case 3:break;
- default:cout<<"Inavalid choice";
- }
- }
- else if(opt==2)
- {
- clrscr();
- cout<<"Passenger Menu";
- cout<<"\n\n\t1.)Book a Ticket\n\t2.)Check ticket info by pnr\n\t3.)Exit";
- cin>>opt2;
- switch(opt2)
- {
- case 1:bookticket();
- break;
- case 2:showticketbypnr();
- break;
- case 3:
- default:break;
- }
- }
- } //Outermost while bracket
- }
- int main()
- {
- clrscr();
- /*train t;
- //storetrain();
- //storetrain();
- showalltrain();
- reserv r;
- bookticket();*/
- menu();
- return 0;
- }
Add Comment
Please, Sign In to add comment