Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<string.h>
- #include<stdio.h>
- #include<time.h>
- #include<iomanip>
- #include<process.h>
- using namespace std;
- char f[2]="f";
- char s[2]="s";
- int addr,ad,flag=1,f1,d,m,i,amt;
- float tamt;
- /*class login
- {
- public:
- char id[2];
- char pass[30];
- char *password;
- void getid();
- void displayid();
- };
- void login::getid()
- {
- cout<<"Enter ID";
- gets(id);
- password=getpass("enter password:");
- strcpy(pass,password);
- }
- void login::displayid()
- {
- cout<<"User ID information:"<<endl<<endl;
- cout<<"ID";
- puts(id);
- cout<<endl;
- cout<<"Password:";
- puts(pass);
- }*/
- class detail
- {
- public:
- int tno;
- char tname[24],bp[20],dest[20],c1,c1fare,c2,c2fare;
- int d,m,y;
- void getdetail();
- void displaydetail();
- };
- void detail::displaydetail()
- {
- cout<<"............................................";
- cout<<".............................................................";
- cout<<"Tr No| Tr Name | Start | Destin|";
- cout<<"FC se | SC se| Fr FC| Fr SC| Date of jo";
- cout<<"\n..........................";
- cout<<".........................................\n";
- cout<<tno<<" "<<tname<<" "<<bp<<" "<<dest<<" "<<c1<<" "<<c2;
- cout<<" "<<c1fare<<" "<<c2fare<<" "<<d<<"/"<<m<<"/"<<y<<endl;
- cout<<"....................................................";
- cout<<"...................................................................";
- }
- void detail::getdetail()
- {
- cout<<"Enter the detail as follows"<<endl;
- cout<<"train number";
- cin>>tno;
- cout<<"Train name";
- gets(tname);
- cout<<"boarding point";
- gets(bp);
- cout<<"Destination point";
- gets(dest);
- cout<<"no of seats in first class"<<endl;
- cout<<"And fare pre ticket:";
- cin>>c1>>c1fare;
- cout<<"number of seats of second class"<<endl<<"and fare per ticket";
- cin>>c2>>c2fare;
- cout<<"Date of travel(in dd/mm/yy):";
- cin>>d>>m>>y;
- }
- class reser : public detail
- {
- public:
- int pnr,tno;
- char tname[30];
- char bp[20],dest[20];
- char pname[100][100];
- int age[20];
- char clas[100];
- int nosr,i,d,m,y,con;
- float amc;
- void getresdet();
- cout<<"Enter class";
- cout<<endl<<"f for first class"<<endl<<"s for second class";
- gets(clas);
- cout<<"date of travel";
- cin>>d>>m>>y;
- cout<<"\n\nenter concessions from below\n";
- cout<<"1.Military \n2.Senior citizen\n";
- cout<<"3.Children below 5 years\n4.none\n";
- cout<<"Enter your choice:";
- cin>>con;
- };
- void reser::getresdet()
- {
- cout<<"Enter the details as follows"<<endl;
- cout<<"train number :";
- cin>>tno;
- cout<<"Train name:";
- gets(tname);
- cout<<"Boarding point";
- gets(bp);
- cout<<"detination point";
- gets(dest);
- cout<<"No of seats required:";
- cin>>nosr;
- for(i=0;i<nosr;i++)
- {
- cout<<"Passenger("<<i+1<<")name:";
- gets(pname[i]);
- cout<<"Passenger("<<i+1<<")age:";
- cin>>age[i];
- }
- }
- void displayresdet()
- {
- cout<<endl;
- cout<<"...........................................................\n";
- cout<<" RESERVATION STATUS \n";
- cout<<"...........................................................\n";
- cout<<"PNR number :"<<pnr<<endl;
- cout<<"Train number :"<<tno<<endl;
- cout<<"Train name :"; puts(tname);
- cout<<"Boarding point :"; puts(bp);
- cout<<"Destination point :"; puts(dest);
- cout<<"number of seats reserved :"<<nosr<<endl;
- for(i=0;i<nosr;i++)
- {
- cout<<"Passenger"<<i+1<<"name:";
- puts(pname[i]);
- cout<<"passenger"<<i+1<<"age";
- }
- cout<<"your class"; puts(clas);
- cout<<"dat of resevation:"<<d<<"/"<<m<<"/"<<y;
- cout<<endl<<"your concession category:"<<con;
- cout<<"\n you must pay:"<<amc<<endl;
- cout<<"..................................................................\n";
- cout<<" END OF RESERVATION DETAILS OF PASSENGER \n";
- cout<<"..................................................................\n";
- }
- class canc:public detail
- {
- public:
- int pnr,tno;
- char tname[200],bp[20],dest[30],pname[10][100];
- int age[100];
- int i;
- char cins[100];
- char clas[100];
- int nasc;
- int d,m,y;
- float amc;
- void getcancdet()
- {
- cout<<"\n\n Enter the details as follows \n";
- cout<<"\nPNR number:";
- cin>>pnr;
- cout<<"\n Date of cancellation:";
- cin>>d>>m>>y;
- }
- void canc::displaycancdet()
- {
- cout<<"..........................................\n";
- cout<<" DISPLAY OF CANCELLTION\N";
- cout<<".........................................\N";
- cout<<"pnr number:"<<pnr<<endl;
- cout<<"Train number :"<<tno<<endl;
- cout<<"train name:"; puts(tname);
- cout<<"Boarding point:"; puts(bp);
- cout<<"Destination point: "; puts(dest);
- cout<<"your class:";puts(clas);
- cout<<"No of seats has been cancelled: "<<nasc<<endl;
- for(i=0;i<nasc;i++)
- {
- cout<<"Passenger name :";
- puts(pname[i]);
- cout<<"Passenger age :"<<age[i]<<endl;
- }
- cout<<"Date of cancellation:"<<d<<"/"<<m<<"/"<<y;
- cout<<"you can collect :Rs."<<amc<<endl;
- cout<<".........................................\n";
- cout<<" END OF CANCELLATION \n";
- cout<<".........................................\n";
- }
- void manage();
- void can();
- void user();
- void database();
- void reser();
- void displaypassdate();
- void cancel();
- void enquiry();
- };
- int main()
- {
- int ch;
- canc object;
- do
- {
- cout<<".............................................................\n";
- cout<<" WELCOME TO ONLINE RESERVATION SYSTEM \n";
- cout<<"............................................................\n";
- cout<<"\n\n.................................................\n";
- cout<<"MAIN MENU \n";
- cout<<".......................................................\n";
- cout<<"\n\\n Admission \n\n1.Admin mode \n 2.User mode\n\n3.Exit\n";
- cout<<"Enter your choice \n";
- cin>>ch;
- cout<<endl;
- switch(ch)
- {
- case 1:
- object.database();
- break;
- case 2:
- object.user();
- break;
- case 3:
- exit(0);
- }
- }while(ch<=3);
- }
- void database()
- {
- char *password;
- char *pass="abc";
- password=getpass();
- detail a;
- int ch;
- char c;
- if(strcmp(pass,password)!=0)
- {
- char c;
- do
- {
- cout<<"\n............................................................\n";
- cout<<"\n Adminsita \n";
- cout<<".......................................";
- cout<<"\n\n1.Add details \n";
- cout<<"\n2.Display details\n\n3.user management\n";
- cout<<"\n4.Display passenger details \n\n5. return to main menu \n";
- cout<<"\n Enter your choice:";
- cin>>ch;
- cout<<endl;
- switch(ch)
- {
- case 1:
- f.open("t.txt",ios::in|ios::out|ios::binary|ios::app);
- do
- {
- a.getdetail();
- f.write((char*)&a,sizeof(a));
- cout<<"\n\nDo you want to add one more record?\n";
- cout<<"y-Yes\n n-No\n";
- cout<<"Your answer:";
- cin>>c;
- }
- while(c=='y')
- f.close();
- break;
- case 2:
- 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 3:
- manage();
- break;
- case 4:
- displaypassdetail();
- break;
- default:
- cout<<"INVALID CHOICE";
- }
- }while(ch<=4);
- f.close();
- }
- }
- void reserve()
- {
- int ch;
- do
- {
- cout<<"1.reserve\n\n.2return to main menu";
- cout<<"Enter your choice:";
- cin>>ch;
- cout<<endl;
- switch(ch);
- {
- case 1;
- res();
- break;
- case 2:
- default:
- cout<<"INVALID CHOICE";
- }
- }
- 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;
- addrf1.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<<"\nconcession category:MILITARY PERSONNEL\n";
- b.amc=b.nosr*((amt*50)/100);
- }
- else if(b.con==2)
- {
- cout<<"\nconcession category:SENIOR CITIZEN\n";
- b.amc=b.nosr*((amt*60)/100);
- }
- else if(b.con==3)
- {
- cout<<"\nconcession category:CHILDREN BELOW FIVE\n";
- b.amc=0.0;
- }
- else if(b.con==4)
- {
- cout<<"\nyou can not get any concession \n";
- b.amc=b.nosr*amt;
- }
- s.rand(unsigned)time(&t));
- b.pnr=rand();
- f2.write((*char)&b.sizef(b));
- b.displayresdet();
- cout<<"......................................................................\n";
- cout<<" YOUR TICKET HAS BEEN RESERVED \n";
- cout<<".......................................................................\n";
- }
- else
- {
- cout<<".......................................................................\n";
- cout<<" SORRY REQUESTED SEATS ARE NOT AVAILABLE \n";
- cout<<"........................................................................\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-95*ad0);
- a.c2=a.c2-b.nosr;
- f1.write((char*)&a.c2,sizeof(a.c2));
- if(b.con==1)
- {
- cout<<"\nconcession category:MILITARY PERSONNEL\N";
- b.amc=b.nosr*((amt*50)/100);
- }
- else if(b.con==2)
- {
- cout<<"\nconcession category:SENIOR CITIZEN\n";
- b.amc=b.nosr*((amt*60)/100);
- }
- else if(b.con==3)
- {
- cout<<"\nconcession category:CHILDREN BELOW FIVE\N";
- b.amc=0.0;
- }
- else if(b.con==4)
- {
- cout<<"\nyou can get no concession\n";
- b.amc=b.nosr*amt;
- }
- f2.write((char*)&b.sizeof(b));
- b.displayresdet();
- cout<<"........................................................\n";
- cout<<" YOUR TICKET HAS BEEN RESERVED \n";
- cout<<".........................................................\n";
- }
- else
- {
- cout<<"........................................................\n";
- cout<<" SORRY REQUIRED SEATS ARE NOT AVAILABLE\n";
- }
- }
- goto h;
- }
- else
- {
- flag=0;
- }
- }
- if(flag==0)
- {
- cout<<"..........................................\n";
- cout<<"wrong train number \n";
- cout<<"..........................................\n";
- cout<<"Enter train number from database\n";
- cout<<".......................\n";
- }
- f1.close();
- f2.closw();
- h:
- }
- void displaypassdetail()
- {
- fstream f;
- reser b;
- f.open("p.txt",ios::in|ios::out|ios::binary);
- f.seekg(0);
- while(f.reas((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 cancel()
- {
- detail a;
- reser b;
- conc a;
- 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<<".............................................................\n";
- cout<<" CANCELLATION MENU \n";
- cout<<".............................................................\n";
- c.getcancdet();
- while(f2.read((char*)&b.sizeof(b)))
- {
- if(b.pnr==c.pnr)
- {
- c.tnc=b.tnc;
- strcpy(c.tname,b.tname);
- strcpy(c.bp,b.bp);
- strcpy(c.dest,b.dest);c.nasc=b.nasr;
- for(int j=0;j<.nasc;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.nasc;
- 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));
- t.amt=b.amc;
- if(c.d==d)&&(c.m==m))
- {
- cout<<"you are cancelling at the date of departure"<<endl;
- c.amr=t.amt-((t.amt*60)/100);
- }
- else if(c.m==m)&&(c.d<d))
- {
- cout<<"you are acnelling in the date of departure"<<endl;
- c.amr=t.amt-((t.amt*50)/100);
- }
- else if(m>c.m)
- {
- cout<<"your are cancelling"<<m-c.m<<"month before the date of depertaure"<<Endl;
- c.amr=t.amt-((t.amt*20)/100);
- }
- else
- {
- cout<<"you are cancelling after the departure"<<endl;
- cout<<"your request cannot be completed"<<endl;
- }
- fstream fp2;
- fp2.open("temp.dat",ios::out);
- f2.seekg(o,ios::beg);
- while(f2.read((char*)&b.sizeof(b)))
- {
- if(b.pnr!=c.pnr)
- {
- fp2.write((char*)&b.sizeof(b));
- }
- }
- fp2.close();
- remove("p.txt");
- rename("temp.dat","p.txt");
- c.displaycandet();
- goto h;
- }
- }
- }
- 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.teelg();
- ad=sizeof(a.c2);
- f1.seekp(addr-(5*ad));
- f1.write((char*)&a.c2,sizeof(a.c2));
- t.amt=b.amc;
- if((c.d==d)&&(c.m==m))
- {
- cout<<"you are cancelling at the date of departure"<<endl;
- a.amr=t.amt-((t.amt*60)/100);
- }
- else if(c.m==m)&&(c.d<d))
- {
- cout<<"you are cancelling at the month of deperture"<<endl;
- c.amr=t.amt-((t.amt*50)/100);
- }
- else if(m>c.m)
- {
- cout<<"you are cancelling"<<m-c.m<<"month before the date of departure"<<endl;
- c.amr=t.amt-((t.amt+20)/100);
- }
- else
- {
- cout<<"you are cancelling after the departure"<<endl;
- cout<<"your request cannot be completed"<<wndl;
- }
- fstream fp2;
- fp2.open("Temp.dat",ios::out);
- f2.seekg(0,ios::beg));
- while(f2.read((char*)&b.sizeof(b)))
- {
- if(b.pnr!=c.pnr)
- {
- fp2.write((char*)&b.sizeof(b));
- }
- }
- fp2.close();
- remove("p.txt");
- rename("Temp.dat","p.txt");
- c.displaycancdet();
- goto h;
- }
- }
- }
- }
- else
- {
- flag=0;
- }
- }
- h;
- if(flag==0)
- {
- cout<<"\nEnter the correct pnr number \n";
- }
- f1.close();
- f2.close();
- f3.close();
- }
- void can()
- {
- int ch;
- do
- {
- cout<<"............................................................\n";
- cout<<"CANCELLATION MENU";
- cout<<"...........................................................\N";
- cout<<"\n\n1.Cancel\n\n2.Return to main menu\n";
- cout<<"\nEnter your choice\n";
- cin>>ch;
- cout<<endl;
- switch(ch)
- {
- case 1:
- cancel();
- break;
- }
- }
- while(ch==1);
- }
- void user()
- {
- login a;
- int ch;
- cout<<"\n........................................................\n";
- cout<<" USER MENU \n";
- cout<<"..........................................................\n";
- char*password;
- fstream f;
- f.open("id.txt",ios::in||ios::out||ios::binary);
- cahr id[100];
- cout<<"\n\n Enter your ID:";gets(id);
- password=getpass("\n\n Enter your password:");
- while(f.read((char*)&a.sizeof(a)))
- {
- if((strcmp(a.id.id)==0)&&(strcmp(a.pass,p.password)==0))
- {
- do
- {
- cout<<"\n\n1.Reserve aticket \n\n2.Cancel a ticket";
- cout<<"\n\n3.Enquiry \n\n4.Return to main menu\n";
- cout<<"\nEnter your choice:";
- cin>>ch;
- cout<<endl;
- switch(ch);
- {
- case 1:
- reserve();
- break;
- case 2:
- cancel();
- break;
- case 3:
- enquiry();
- break;
- }
- }
- while(ch>=3)
- goto j;
- }
- else
- {
- d=1;
- }
- }
- if(d==1)
- {
- cout<<"\nEnter user id and password correct \n";
- }
- }
- void manage()
- {
- int ch;
- fstream f;
- char c;
- login a;
- cout<<"...................................................................\n";
- cout<<"WELCOME TO USER MANAGEMENT MENU\N";
- cout<<"...................................................................\N";
- do
- {
- cout<<"\n\n1.add ID details of user \n";
- cout<<"\n2.Display details of Id \n\n3.return to main menu \n";
- cout<<"\nEnter your choice :";
- cin>>Ch;
- cout<<endl;
- switch(ch)
- {
- case 1:
- f.open("id.txt",ios::in||ios::out||ios::binary||ios::app);
- do
- {
- a.getid();
- f.write((char*)&a.sizepf(a));
- cout<<"\n\nDo you want to add one more record\n";
- cout<<"y-Yes\nn-No\n";
- cout<<"Your answer \n";
- cin>>c;
- }while(c=='Y');
- f.close();
- break;
- case 2:
- 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<=2;)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement