|
Having problem in calling functions inthe main
I need to create a e-railway ticketing system with the functions of
1) Adding train details
2) Passenger details -> a)booking ticket
b)cancel ticket
c)waiting
3) Main->calling the above functions
I have created the train details where i will key in the details, and passenger datails where the user will enter information on booking the ticket.
The problem Im having is i dont know how to call all these function in the main. Can someone help me to do this. Thank You in advance.
The following is my coding: *If I did any mistaken in the coding please let me know. :-D
//Create train details
#include <fstream.h>
#include <string.h>
#include <iostream.h>
//using namespace std;
fstream trainfile("Train.dat", ios::in||ios::app);
class train
{
char trainno[10], startst[30], desst[30];
int sits;
public:
int getseats()
{
return sits;
}
train()
{
trainfile.open("Train.dat",ios::in|ios::app);
}
int findtrain(char *t)
{
return strcmp(trainno,t);
}
void modify(int seat,char sg)
{
if(sg =='-')
sits-=seat;
else
sits+=seat;
}
void keydata()
{
trainfile.open("Train.dat",ios::app);
cout<<"\tADD NEW TRAIN DETAILS\n\n";
cout<<"Enter Train Number: ";
cin>>trainno;
cout<<"Enter starting Station: ";
cin>>startst;
cout<<"Enter Destination Station: ";
cin>>desst;
cout<<"Enter Number Of Sit: ";
cin>>sits;
trainfile.write((char *)this,sizeof(this));
trainfile.close();
}
void disp()
{
cout<<"\tTRAIN SCHEDULE\n\n";
cout<<"\tTRAIN NO:"<<trainno<<"\ttrstartING STATION:"<<startst<<"\tDESTINATION STATION:"<<desst<<"\tNUMBER OF SIT:"<<sits<<endl;
}
train *prev, *next;
} *trstart, *trtmp, *trcur;
void adddata()
{
train *rec=new train;
rec->keydata();
rec->next=NULL;
rec->prev=NULL;
if(trstart==NULL)
trstart=rec;
else
{
for(trcur=trstart; trcur->next!=NULL; trcur=trcur->next);
trcur->next=rec;
}
}
void dispalldata()
{
trainfile.open("Train.dat",ios::in);
while(!trainfile.eof())
{
train *rec=new train;
trainfile.read((char*)rec,sizeof(train));
if(trstart==NULL)
trstart=rec;
else
{
for(trcur=trstart;trcur->next !=NULL;trcur=trcur->next);
trcur->next=rec;
}
}
trainfile.close();
for(trcur = trstart;!(trcur);trcur=trcur->next)
trcur->disp();
}
void findtrainno()
{
char tr[30];
cout<<"Enter train number: ";
cin>>tr;
for(trcur=trstart; trcur; trcur=trcur->next)
{
if(trcur->findtrain(tr)==0)
{
trcur->disp();
break;
}
}
if(trcur==NULL)
cout<<"INVALID TRAIN NUMBER "<<tr<<" IN THE LIST\n";
}
void main()
{
trstart=NULL;
char ch;
do
{
cout<<"\tTRAIN DETAILS\n";
cout<<"1. ADD NEW TRAIN DETAILS\n";
cout<<"2. DISPLAY ALL TRAIN DETAILS\n";
cout<<"3. FIND TRAIN NUMBER\n";
cout<<"4. EXIT\n\n";
cout<<"\tENTER YOUR CHOICE: ";
cin>>ch;
switch(ch)
{
case '1': adddata();
break;
case '2': dispalldata();
break;
case '3': findtrainno();
break;
}
}while(ch<'4');
cout<<"\tTHANK YOU";
}
// Passenger details
#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<stdio.h>
#include "train details.cpp"
//using namespace std;
fstream psgrFile("Passenger.dat",ios::in||ios::app);
class passenger
{
private:
char PSfname[50], PSlname[50], PSsex[2], PSadd[50], PSphone[50],ans;
int PSage;
protected:
char PNR[7],tmpPNR[7];
public:
char trainno[10];
void details()
{
cout<<"\tEnter Passenger Details\n ";
cout<<"First Name:\t";
cin>>PSfname;
cout<<"Last Name:\t";
cin>>PSlname;
cout<<"PSsex:\t";
cin>>PSsex;
cout<<"PSage:\t";
cin>>PSage;
cout<<"PSaddress:\t";
cin>>PSadd;
cout<<"Train Number : ";
cin>>trainno;
cout<<"Contact Number:\t";
cin>>PSphone;
getPNR();
cout<<"Confirm? ";
cin>>ans;
if(ans =='y')
writetofile();
}
void writetofile()
{
int nos;
char flg='n';
for(trcur=trstart;!trcur;trcur=trcur->next)
{
if(trcur->findtrain(trainno)==0)
{
flg= 'y';
nos = trcur->getseats();
cout<<"\tYOUR TICKET IS BOOK\n";
break;
}
else
flg='n';
if(flg=='y')
{
if(nos > 0)
{
trcur->modify(1,'-');
psgrFile.open("passengers.dat",ios::app);
psgrFile.write((char *)this,sizeof(this));
psgrFile.close();
}
else
{
cout<<"Sorry! FULLY BOOK. Your reservation will be in waiting list\n";
// open the waiting list file...
//and write the current ticket information in there.
}
}
else
cout<<"Sorry! no such train no: "<<trainno<<" found in the list....\n";
}
}
void readfile()
{
psgrFile.open("passengers.dat",ios::in);
psgrFile.read((char *)this,sizeof(this));
psgrFile.close();
}
void getPNR()
{
psgrFile.open("passenger.dat",ios::ate);
int pos = psgrFile.tellg();
if(pos == 0)
strcpy(PNR,"SHS001");
else
{
psgrFile.open("passenger.dat",ios::in);
while(!psgrFile.eof())
{
psgrFile.read((char *)this,sizeof(this));
}
int alen, blen, num,cr=0;
char midl[3];
for(int ctr=3;PNR[ctr]!='\0';ctr++,cr++)
{
tmpPNR[cr]=PNR[ctr];
tmpPNR[cr]='\0';
blen=strlen(tmpPNR);
num=atoi(tmpPNR);
num++;
sprintf(tmpPNR,"%d",num);
alen=strlen(tmpPNR);
ctr=0;
}
while(alen < blen)
{
midl[ctr]='0';
ctr++;
alen++;
}
midl[ctr]='\0';
sprintf(PNR,"SHS%s%d",midl,num);
}
}
void cancel(char *t,int s )
{
char flg;
for(trcur=trstart;!trcur;trcur=trcur->next)
{
if(trcur->findtrain(t)==0)
{
flg='y';
trcur->modify(1,'+');
break;
}
}
}
void display()
{
cout<<"\t\tSRISHA RAILWAY E-TICKETING\n\n";
cout<<"\tRESERVATION SLIP\n";
cout<<"\tPASSENGER DETAILS\n";
cout<<"---------------------------------------------------------\n";
cout<<"PNR: "<<PNR<<endl;
cout<<"First Name: "<<PSfname<<"\tLast Name: "<<PSlname<<endl;
cout<<"PSsex: "<<PSsex<<"\tContact Number: "<<PSphone<<endl;
cout<<"PSaddress: "<<PSadd<<endl;
cout<<"Train Number: "<<trainno<<endl;
}
int findpnr(char *s)
{
return strcmp(PNR,s);
}
passenger *next;
}*start, *tmp, *cur;
void cancelticket()
{
char pnr[7], flg;
cout<<"Enter the PNR to cancel :";
cin>>pnr;
for(cur=start;!cur;cur=cur->next)
{
if(cur->findpnr(pnr) == 0)
{
cur->cancel(cur->trainno,1);
flg='y';
break;
}
else
flg='n';
}
if(flg=='n')
cout<<"Sorry! There is no tickets issued with the pnr "<<pnr<<endl;
}
#include<iostream.h>
#include<string.h>
#include "passenger details.cpp"
//using namespace std;
void ticketing()
{
char cho;
passenger sh;
do
{
cout<<"\t\tSRISHA E-TICKETING\n\n";
cout<<"\t1. BOOKING\n";
cout<<"\t2. WAITING LIST\n";
cout<<"\t3. CANCELLATION\n";
cout<<"\t4. MAIN MENU\n\n";
cout<<"\tENTER YOUR CHOICE:\t";
cin>>cho;
switch(cho)
{
case '1': sh.details();
break;
case '2': sh.writetofile();
break;
case '3': cancelticket();
break;
}
}while(cho<'4');
}
void report()
{
}
void trains()
{
char ch;
do
{
cout<<"\tTRAIN DETAILS\n";
cout<<"1. ADD NEW TRAIN DETAILS\n";
cout<<"2. DISPLAY ALL TRAIN DETAILS\n";
cout<<"3. FIND TRAIN NUMBER\n";
cout<<"4. EXIT\n\n";
cout<<"\tENTER YOUR CHOICE: ";
cin>>ch;
switch(ch)
{
case '1': adddata();
break;
case '2': dispalldata();
break;
case '3': findtrainno();
break;
}
}while(ch<'4');
cout<<"\tTHANK YOU";
}
void main()
{
//trstart=NULL;
char ch1;
do
{
cout<<"\t\tSRISHA RAILWAY SYSTEM \n\n";
cout<<"\t1. SRISHA TRAIN SCHEDULE\n";
cout<<"\t2. SRISHA E-TICKETING\n";
cout<<"\t3. SRISHA REPORT (AUTHORISE)\n";
cout<<"\t4. EXIT\n\n";
cout<<"\tENTER YOUR CHOICE:\t";
cin>>ch1;
switch(ch1)
{
case '1': trains();
break;
case'2': ticketing();
break;
case '3': report();
break;
}
}while(ch1<'4');
cout<<"\t\tTHANK YOU FOR USING\n\t SRISHA RAILWAY SYSTEMS\n\n";
//return 0;
}
|