i am working on a airport reservation program and i have run into a brick wall. i want to ask the user its name,gender,passport no,age, destination, and travel class and figure out the day and flight code of the flight which i have saved in a binary file. now every thing works fine except the code and the day. could you help me figure out the problem.
the programs important section
the flight class
Code:
class flights
{
char code[9],location[21];
public:
void display();
char *retloc() //to get the Location
{return location;}
char *retcode() //to get the flight code
{return code;}
};
the ticket class
Code:
class ticket //Class ticket {
private:
char name[50]; //Passenger's name
char p_num[25]; //Passport number
char des[50]; //Destination
char sex; //Gender of passenger
char day[9];
char code[9];
int age; //Age of passenger required for finding cost of ticket
int t_class; //Travel class
float price; //Price of ticket
public:
void enter();
float expence(int t_c,int old);
void display();
char *get_num() //To get passport number for
{return p_num;} // enquire function
float get_price() //To get price of indivisual ticket
{return price;} // for calculating total cost
}; //End of class ticket
the enter function
Code:
void ticket::enter() //Enter function
{
cout<<"Personal Information\n\n";
cout<<"Enter passenger's name: ";
gets(name);
cout<<"\nEnter passport number: ";
gets(p_num);
cout<<"\nEnter passenger's age: ";
cin>>age;
cout<<"\nEnter passenger's gender(M/F): ";
cin>>sex;
clrscr();
cout<<"Flight Information"<<endl<<endl;
cout<<"Enter destination: ";
gets(des);
cout<<"\nSelect type of travel class: "<<endl;
cout<<"1)First Class"<<endl;
cout<<"2)Business Class"<<endl;
cout<<"3)Economy Class"<<endl;
cout<<endl;
cout<<"Choice: ";
cin>>t_class;
price=expence(t_class,age);
int len=strlen(des);
for(int j=0;j<20-len;j++)
strcat(des," ");
fstream f1;
flights f;
f1.open("Flight_Record.dat",ios::in|ios::binary);
while(f1.read((char*)&f,sizeof(f)))
if(!strcmp(des,f.retloc()))
strcpy(code,f.retcode());
f1.close();
fstream f2;
for(int i=0;i<7;i++)
{
if(i==0)
{
f2.open("Flight_RecordSunday.dat",ios::in|ios::binary);
while(f2.read((char*)&f,sizeof(f)))
if(!strcmp(code,f.retcode()))
{
strcpy(day,"SUNDAY");
f2.close();
return;
}
}
if(i==1)
{
f2.open("Flight_RecordMonday.dat",ios::in|ios::binary);
while(f2.read((char*)&f,sizeof(f)))
if(!strcmp(code,f.retcode()))
{
strcpy(day,"MONDAY");
f2.close();
return;
}
}
if(i==2)
{
f2.open("Flight_RecordTuesday.dat",ios::in|ios::binary);
while(f2.read((char*)&f,sizeof(f)))
if(!strcmp(code,f.retcode()))
{ strcpy(day,"TUESDAY");
f2.close();
return;
}
}
if(i==3)
{
f2.open("Flight_RecordWednesday.dat",ios::in|ios::binary);
while(f2.read((char*)&f,sizeof(f)))
if(!strcmp(code,f.retcode()))
{ strcpy(day,"WEDNESDAY");
f2.close();
return;
}
}
if(i==4)
{
f2.open("Flight_RecordThursday.dat",ios::in|ios::binary);
while(f2.read((char*)&f,sizeof(f)))
if(!strcmp(code,f.retcode()))
{ strcpy(day,"THURSDAY");
f2.close();
return;
}
}
if(i==5)
{
f2.open("Flight_RecordFriday.dat",ios::in|ios::binary);
while(f2.read((char*)&f,sizeof(f)))
if(!strcmp(code,f.retcode()))
{ strcpy(day,"FRIDAY");
f2.close();
return;
}
}
if(i==6)
{
f2.open("Flight_RecordSaturday.dat",ios::in|ios::binary);
while(f2.read((char*)&f,sizeof(f)))
if(!strcmp(code,f.retcode()))
{ strcpy(day,"SATURDAY");
f2.close();
return;
}
}
f2.close();
}
}
the display function
Code:
void ticket::display() //Display function
{
clrscr();
cout<<"Name: ";
puts(name);
cout<<"\nPassport Number: ";
puts(p_num);
cout<<"\nAge: "<<age<<endl;
cout<<"Sex: "<<sex<<endl;
cout<<"From: Kuwait"<<endl;
cout<<"To: ";
puts(des);
cout<<"\nDay: ";
puts(day);
cout<<"\nCode: "<<code;
cout<<"\nTravel Class: ";
switch(t_class)
{
case 1:cout<<"First Class"<<endl;
break;
case 2: cout<<"Bussiness Class"<<endl;
break;
case 3:cout<<"Economy Class"<<endl;
break;
}
cout<<endl;
cout<<"Price: "<<price<<" KD\n";
}
the main problem section is in the ticket entry section