I was given this project as a part of my school assignment, please note that I have very limited knowledge of the language, and my teacher won't allow using anything other than what is used in the following code (Crappy 12th grade curriculum:yawn:)...
Here is my complete code, its in premature stage, and I haven't considered the seating constraints yet,, on compiling it gives DECLARATION TERMINATED INCORRECTLY ERROR!!,i am planning to run this and correct errors as they come, but its not going to run untill that error is removed... Please help!.:icon_eek:
#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
class mainmenu
{
public:
void title()
{
cout << "######################################################"<< endl;
cout << "######## WELCOME TO INDIAN AIRLINES ##############"<< endl;
cout << "######################################################"<< endl;
cout << " "<< endl;
}
void showMainMenu()
{
cout << "1. AIRLINE INFORMATION MENU (For Airline Staff Members)"<< endl;
cout << "2. PASSENGER MENU (For reservation/cancellation)" << endl;
cout << "3. EXIT PROGRAM" << endl;
cout << "Enter a selection [valid choices are 1, 2, 3]: ";
int x;
cin>>x;
}
void showFlightMenu()
{
cout <<" " << endl;
cout <<"WELCOME TO FLIGHT MENU"<< endl;
cout <<"1. ADD a Flight" << endl;
cout <<"2. DELETE a Flight" << endl;
cout <<"3. QUERRY a Flight" << endl;
cout <<"4. RETURN to MAIN MENU" << endl;
cout << "Enter a selection [valid choices are 1, 2, 3, 4]: ";
int y;
cin>>y;
}
void showPassengerMenu()
{
cout <<" " << endl;
cout <<"WELCOME TO PASSENGER MENU"<< endl;
cout <<"1. Make a Reservation" << endl;
cout <<"2. Cancel an Existing Reservation" << endl;
cout <<"3. View an Existing Reservation" << endl;
cout <<"4. RETURN to MAIN MENU" << endl;
cout << "Enter a selection [valid choices are 1, 2, 3, 4]: ";
int z;
cin>>z;
}
void menu()
{
bool quitMainMenu=false;
bool quitFlightMenu;
bool quitPassengerMenu;
while (quitMainMenu != true)
{
showMainMenu();
quitFlightMenu=false;
quitPassengerMenu=false;
switch (x)
{
case '1':
while (quitFlightMenu != true)
{
showFlightMenu();
switch (y)
{
case '1':
cout << "Adding a new Flight" << endl;
AddFlight();
break;
case '2':
cout << "Deleting a Flight" << endl;
DeleteFlight();
break;
case '3':
cout << "Querrying a Flight" << endl;
EnquireFlight();
break;
case '4':
cout << "Returning to Main Menu" << endl;
quitFlightMenu=true;
break;
default:
cout << "Invalid Flight Menu Selection" << endl;
break;
}
}
break;
case '2':
while (quitPassengerMenu != true)
{
showPassengerMenu();
switch (z)
{
case '1':
cout << "New Reservation" << endl;
Check();
break;
case '2':
cout << "Cancellation" << endl;
Cancel();
break;
case '3':
cout << "Viewing an existing reservation" << endl;
ViewRegistration();
break;
case '4':
cout << "Returning to Main Menu" << endl;
quitPassengerMenu=true;
break;
default:
cout << "Invalid Passenger Menu Selection" << endl;
break;
}
}
break;
case '3':
cout << "Thank you for visiting Indian Airlines" << endl;
//exit (1);
quitMainMenu=true;
break;
default:
cout << "Invalid selection" << endl;
break;
}
}
};
class Flight
{
char flight_id[4];
int capacity_economy;
int capacity_firstclass;
int date;
int mon;
char source[25];
char destination[25];
int e_fare;
int f_fare;
public:
void EnterDetails()
{
cout<<"Enter Flight Id = ";
gets(flight_id);
cout<<endl<<"Enter Flight's Capacity = ";
cout<<endl<<"Economy = ";
cin>>capacity_economy;
cout<<endl<<"First Class = ";
cin>>capacity_firstclass;
cout<<endl<<" Enter date and month respectively";
cin>>date>>mon;
cout<<endl<<" Enter Source = ";
gets(source);
cout<<endl<<" Enter Destination = ";
gets(destination);
cout<< "Enter fare for economy class: " << endl;
cin>>e_fare;
cout<< "Enter fare for first class: " << endl;
cin>>f_fare;
}
void AddFlight()
{Flight f1;
char ch;
ofstream fout("Flight Records.txt",ios::app);
while(ch=='y')
{
f1.EnterDetails();
fout.write((char*)&f1,sizeof(f1));
cout<<"Want to enter more records ? (y/n)" ;
cin>>ch;
}
fout.close();
}
void EnquireFlight()
{Flight f1;
char id[4];
ifstream fin("Flight Records.txt");
cout<<"Enter Flight Id = ";
gets(id);
if(!fin)
{
cout<<"File doesn't exists ";
exit(0);
}
while(!fin.eof())
{
fin.read((char*)&f1,sizeof(f1));
if(strcmp(f1.flight_id,id)==0)
{
cout<<"Flight Id = ";
puts(f1.flight_id);
cout<<endl<<"Flight's Capacity = ";
cout<<endl<<"Economy = ";
cout>>f1.capacity_economy;
cout<<endl<<"First Class = ";
cout>>f1.capacity_firstclass;
cout<<endl<<" Date and month respectively of departure";
cout<<f1.date<<" "<<f1.mon;
cout<<endl<<"Source = ";
puts(f1.source);
cout<<endl<<"Destination = ";
puts(f1.destination);
cout<<endl<< "Fare for economy class: " << endl;
cout<<f1.e_fare;
cout<<endl<< "Fare for first class: " << endl;
cout<<f1.f_fare;
}
else
cout<<"Flight doesn't exists !";
}
fin.close();
}
void DeleteFlight()
{Flight f1;
char confirm;
char id[4];
ifstream fin("Flight Records.txt");
ofstream fout("Temp.txt");
cout<<"Enter Flight Id = ";
gets(id);
if(!fin)
{
cout<<"File doesn't exists ";
exit(0);
}
while(!fin.eof())
{
fin.read((char*)&f1,sizeof(f1));
if(strcmp(f1.flight_id,id)==0)
{cout<<"Found the record ";
cout<<endl<<"Flight Id = ";
puts(f1.flight_id);
cout<<endl<<"Flight's Capacity = ";
cout<<endl<<"Economy = ";
cout>>f1.capacity_economy;
cout<<endl<<"First Class = ";
cout>>f1.capacity_firstclass;
cout<<endl<<" Date and month respectively of departure";
cout<<f1.date<<" "<<f1.mon;
cout<<endl<<"Source = ";
puts(f1.source);
cout<<endl<<"Destination = ";
puts(f1.destination);
cout<<endl<< "Fare for economy class: " << endl;
cout<<f1.e_fare;
cout<<endl<< "Fare for first class: " << endl;
cout<<f1.f_fare;
cout<<endl<<"Are you sure, you want to delete these record? (y/n)";
cin>>confirm;
if (confirm!='y')
fout.write((char*)&f1,sizeof(f1));
}
else
cout<<"Flight doesn't exists !";
}
fin.close();
fout.close();
remove("Flight Records.txt")l
rename("temp.txt","Flight Records.txt");
}
};
class Passenger
{
private:
char first_name[20];
char last_name[20];
char address[40];
char city[20];
char state[20];
int travel_date;
int travel_month;
char psource[20];
char pdestination[20];
int counter;
public:
Passenger()
{
counter=0;
}
void MakeReservation()
{
cout<<"Enter your First Name: ";
gets(first_name);
cout<<endl<<"Enter your Last Name: ";
gets(last_name);
cout<<endl<<"Enter your address: ";
gets(address);
cout<<endl<<"Enter your city: ";
gets(city);
cout<<endl<<"Enter your state: ";
gets(state);
cout<<endl<<"Enter travel date and month respectively ";
cin>>travel_date>>travel_month;
cout<<endl<<" Enter Source = ";
gets(psource);
cout<<endl<<" Enter Destination = ";
gets(pdestination);
}
void See()
{
cout<<"First Name: ";
puts(first_name);
cout<<endl<<"Last Name: ";
puts(last_name);
cout<<endl<<"Address: ";
puts(address);
cout<<endl<<"City: ";
puts(city);
cout<<endl<<"State: ";
puts(state);
cout<<endl<<"Travel date and month respectively ";
cout<<travel_date<<" "<<travel_month;
cout<<endl<<"Source = ";
puts(psource);
cout<<endl<<"Destination = ";
puts(pdestination);
}
void ViewRegistration()
{
Passenger p1;
ind ID;
ifstream fin("Reservations.txt");
if(!fin)
{
cout<<"File doesn't exists ";
exit(0);
}
cout<<"Please enter your registration ID";
cin>>ID;
while(!fin.eof())
{
fin.read((char*)&p1,sizeof(p1));
if(p1.count==ID)
{
cout<<endl<<"Registration Details: ";
p1.see();
}
else
cout<<"Sorry, no such registration exists ";
}
fin.close();
}
void Cancel()
{Passenger p1;
int ID;
char confirm;
ifstream fin("Reservations.txt");
ofstream fout("Temp.txt");
if(!fin)
{
cout<<"File doesn't exists ";
exit(0);
}
cout<<"Please enter your registration ID";
cin>>ID;
while(!fin.eof())
{
fin.read((char*)&p1,sizeof(p1));
if(p1.count==ID)
{
cout<<endl<<"Are you sure, you want to cancel this reservation? (y/n)";
cin>>confirm;
if (confirm!='y')
fout.write((char*)&p1,sizeof(p1));
}
else
cout<<"Flight doesn't exists !";
}
fin.close();
fout.close();
remove("Reservations.txt")l
rename("temp.txt","Reservations.txt");
}
void Check()
{Passenger p1;
Flight f1;
p1.MakeReservation();
ofstream fout("Reservations.txt");
ifstream fin("Flight Records.txt");
if(!fin)
{
cout<<"File doesn't exists ";
exit(0);
}
while(!fin.eof())
{
fin.read((char*)&f1,sizeof(f1));
if(p1.travel_date==f1.date&&p1.travel_month==f1.mon&&strcmpi(p1.psource,f1.source==0)&&strcmpi(p1.pdestination,f1.destination==0))
{
fout.write((char*)&p1,sizeof(p1));
count++;
fout<<count;
cout<<"Registration Successful!, Note the following ID and please contact 0581-2456781 to proceed with payment ";
cout<<endl<<"ID: ";cout<<count;
cout<<endl<<"Please review registration details = ";
p1.see();
}
else
cout<<"Sorry, no such flight is available at the moment";
}
fin.close();
fout.close();
}
};
void main()
{clrscr();
mainmenu m1;
m1.title();
m1.showMainMenu();
m1.menu();
getch();
}
It gives DECLARATION TERMINATED ERROR in the last line... Thank You