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

Recommended Answers

All 15 Replies

Please use proper formatting techniques, especially on indentation. See this and repost.

I think a closing bracket is missing

I think a closing bracket is missing

Yeah, that's one problem. There's a bracket missing on line 159. However, there are many other problems.

  1. You have several typos, where you have hit l instead of ; at the end of a line.
  2. The global functions that you have don't have any prototypes, you need to add
    void AddFlight();
    void EnquireFlight();
    void DeleteFlight();

    to the top of the file (just after the #include statements)

  3. The mainmenu class contains calls to member functions from the Passenger class.
  4. You've used strcmp but you haven't included the header file that it's in
  5. A number of other things

One of your main problems is the general style of the program. I can't emphasise how important is it to have a kind of notation of the names of things and stick to it EVERYWHERE. For example, I would name things like this:

/* This is a function, it starts with a capital letter that isn't a 'C' */
FareCalculator();  

/* This is a local variable, it starts with a lower-case letter. In this case 'd', which indicates it's a double type */
dCurrentFare;   

/* CFlight is a class, it starts with a 'C', myFlight is a variable of non-simple type, since it starts with a lower-case letter */
CFlight myFlight;

/* This is a member variable of whatever class we're in, it starts 'm_'.  We can also tell that it's an int, since the name starts with an 'i' */
m_iCounter;

I would also avoid having complicated logic written directly inside switch... case statements. Make a function that does the stuff you want to do in each case:

switch( iUserChoice )
{
case 1 :
   {
      UserMadeChoice_1();
   }
   break;
case 2 :
   {
      UserMadeChoice_2();
   }
   break;
case 3 :
   {
      UserMadeChoice_3();
   }
   break;
default :
   UserMadeBadChoice();
}

The logic in each of the UserMadeChoice_ functions can be as complicated as you need, we can't change what needs doing when a user makes choice 'x'. However, now people can read and understand what it is that you're trying to do!

Hope that helps. Remember to keep your code as tidy as possible!

Your code reminds me of my early days of programming. :) I had an assignment once, and as a student I was very eager to write it, so I jumped right at it. I started to implement all the functions one by one, and I thought I was doing pretty well, but there was an error I couldn't find. I spent hours and hours to debug it, but I had so many stuff going on it was impossible to figure out, and I ended up not finishing that program ever. :( But, I learned a valuable lesson that day, why it is very important to write maintainable code. That first hand experience of dealing with my own unmaintainable code has changed my coding style forever. I cannot emphasize enough, how important it is to learn proper formatting skills, learn from my mistake. I hope you find your bug.

Wow, thanks a lot for taking the time to correct this, really appreciate your support..
I'll keep in mind the suggestions you gave.
So i did what you said, it removed most of the errors,, but now its giving the following errors,,:
Linker Error: Undefined Symbol Cancel() in module ARMATURE.CPP //"that's my file"
Same with other functions like Check(),AddFlight() etc..
What am i doing wrong now??

Complete corrected code : (Sorry, but i will edit it as soon as i get this up and running:sad:)

#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
void AddFlight();
void EnquireFlight();
void DeleteFlight();
void Check();
void Cancel();
void ViewRegistration();

class mainmenu
{ int x,y,z;

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()
{
	int quitMainMenu=0;
	int quitFlightMenu;
	int quitPassengerMenu;
	while (quitMainMenu!=1)
	{
	showMainMenu();
	quitFlightMenu=0;
	quitPassengerMenu=0;
		switch (x)
		{
			case '1':


				while (quitFlightMenu != 1)
				{
				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=1;
							break;
						default:


							cout << "Invalid Flight Menu Selection" << endl;
							break;
					}
				}
				break;
			case '2':


				while (quitPassengerMenu != 1)
				{
				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=1;
							break;
						default:


							cout << "Invalid Passenger Menu Selection" << endl;
							break;

					}
				}
				break;
			case '3':


				cout << "Thank you for visiting Indian Private Airlines" << endl;
				//exit (1);
				quitMainMenu=1;
				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");
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");
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();
}

Thanks Again

Ah, I appear to have been mistaken before, I thought that the functions AddFlight() , EnquireFlight() and DeleteFlight() were globally accessible, but they're actually member functions of your Flight class. This means that you can't use them in the way that you're trying to. You have to have a Flight object to call those members on, for example you could do:

switch (y)
{
    case '1':
    cout << "Adding a new Flight" << endl;
    Flight myFlight;
    myFlight.AddFlight();
    break;

// Rest of code continues here...

Apart from the fact that it's hard to see what's going on because of the lack of indenting in you post. If the code looks like this on your own computer, then I would expect you to be having problems figuring out what's going on! The other thing that's causing confusion is that you have all your member functions declared and defined at the same time. This makes it hard to see what member variables and functions are in each class. I'd go for declaring your classes like this:

class CFlight
{
public :
   
   /// Add details of to a flight
   void EnterDetails();

   /// Add a flight
   void AddFlight();

   ///  Enquire about flight details
   void EnquireFlight();

private:
   
   char m_cFlight_id[4];
   int m_iCapacity_economy;
   int m_iCapacity_firstclass;
   int m_iDate;
   int m_iMon;
   char m_cSource[25];
   char m_cDestination[25];
   int m_iE_fare;
   int m_iF_fare;
};

So, now it's nice and easy to see what data the class stores and what functions it has. The definitions for the member functions should be in a separate place - either underneath the class, or in an entirely separate file. Like this:

void CFlight::EnterDetails()
{
   cout << "Enter Flight Id = ";
   gets(flight_id);

   cout << endl << "Enter Flight's Capacity = ";
   cout << endl << "Economy = ";
   cin >> m_iCapacity_economy;

   cout << endl << "First Class = ";
   cin >> m_iCapacity_firstclass;

   cout << endl << " Enter date and month respectively";
   cin >> m_iDate >> m_iMon;

   cout << endl << " Enter Source = ";
   gets( m_cSource);

   cout << endl << " Enter Destination = ";
   gets( m_cDestination);

   cout << "Enter fare for economy class: " << endl;
   cin >> m_iE_fare;

   cout << "Enter fare for first class: " << endl;
   cin >> m_iF_fare;
}

White-space can be used to aid readability further (as above). It might not seem like any of this is that important, since the compiler doesn't care about it. However, it's vital for the readability and maintainability of your code.

Thanks for the last post, I got the program running, menu works, and most of the functions do too,,, but there seems to be some problem with AddFlight() and EnterDetails() Functions,, it seems like the compiler is just ignoring what AddFlight() is supposed to do,, i even tried replacing EnterDetails() with use normal cin,,(fout<<) commands, still no luck..:confused: it just jumps back to showFlightMenu().. Thanks again for your time,, I really hope this is the last time you have see this again...
My code::X

#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <process.h>

class Flight;
class Passenger;
class mainmenu
{ int x,y,z;

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]: ";
	
}
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]: ";
	
}
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]: ";
	
}

void menu()
{       char x;
         
	int quitMainMenu=0;
	int quitFlightMenu;
	int quitPassengerMenu;
	while (quitMainMenu != 1)
	{
	showMainMenu();
	cin>>x;
	quitFlightMenu=0;
	quitPassengerMenu=0;
		switch (x)
		{       
			case '1':


				while (quitFlightMenu != 1)
				{ Flight a;
                                  showFlightMenu();
                                  char y;
	                          cin>>y;
				  
					switch (y)
					{
						case '1':


							cout << "Adding a new Flight" << endl;
                                                        
							a.AddFlight();
							break;
						case '2':


							cout << "Deleting a Flight" << endl;
							a.DeleteFlight();
							break;
						case '3':


							cout << "Querrying a Flight" << endl;
							a.EnquireFlight();
							break;
						case '4':


							cout << "Returning to Main Menu" << endl;
							quitFlightMenu=1;
							break;
						default:


							cout << "Invalid Flight Menu Selection" << endl;
							break;
					}
				}
				break;
			case '2':
                                


				while (quitPassengerMenu != 1)
				{ Passenger p;
                                  
				showPassengerMenu();
                                        char z;
 	                                cin>>z;
					switch (z)
					{
						case '1':


							cout << "New Reservation" << endl;
							p.Check();
							break;
						case '2':


							cout << "Cancellation" << endl;
							p.Cancel();
							break;
						case '3':


							cout << "Viewing an existing reservation" << endl;
							p.ViewRegistration();
							break;
						case '4':


							cout << "Returning to Main Menu" << endl;
							quitPassengerMenu=1;
							break;
						default:


							cout << "Invalid Passenger Menu Selection" << endl;
							break;

					}
				}
				break;
			case '3':


				cout << "Thank you for visiting Indian Private Airlines" << endl;
				//exit (1);
				quitMainMenu=1;
				break;
			default:


				cout << "Invalid selection" << endl;
				break;
		}
	}
}

};





class Flight
{
	char flight_id[4];
	int capacity_economy;
	int capacity_firstclass;

	int e_fare;
	int f_fare;
public:
	int date;
	int mon;
	char source[25];
	char destination[25];
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");
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;
	int count;


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;
int 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");
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)
{
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.menu();
getch();
}

Please use proper formatting techniques, especially on indentation. See this and repost.

... But, I learned a valuable lesson that day, why it is very important to write maintainable code. That first hand experience of dealing with my own unmaintainable code has changed my coding style forever. I cannot emphasize enough, how important it is to learn proper formatting skills, learn from my mistake. I hope you find your bug.

Apart from the fact that it's hard to see what's going on because of the lack of indenting in you post. If the code looks like this on your own computer, then I would expect you to be having problems figuring out what's going on!

White-space can be used to aid readability further (as above). It might not seem like any of this is that important, since the compiler doesn't care about it. However, it's vital for the readability and maintainability of your code.

3 different people, same comment. And you are ignoring each of them! Why should we bother?

FORMAT YOUR CODE!

I suggest no one bother trying to dig through his code anymore if he's not going to bother listening. It'll take 10 minutes to format that mess properly, and save us buckets of time trying to be nice helping him for free.

And stop QUOTEing your text. It's not a quote. Just type it in.

Sorry,,, Hope i didn't do much damage,,,
Does this make it any better ?:|

#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <process.h>

class Flight;
class Passenger;
class mainmenu
{ int x,y,z;

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]: ";
	
}
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]: ";
	
}
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]: ";
	
}

void menu()
{       char x;
         
	int quitMainMenu=0;
	int quitFlightMenu;
	int quitPassengerMenu;
	while (quitMainMenu != 1)
	{
	showMainMenu();
	cin>>x;
	quitFlightMenu=0;
	quitPassengerMenu=0;
		switch (x)
		{       
			case '1':


				while (quitFlightMenu != 1)
				{ Flight a;
                                  showFlightMenu();
                                  char y;
	                          cin>>y;
				  
					switch (y)
					{
						case '1':


							cout << "Adding a new Flight" << endl;
                                                        
							a.AddFlight();
							break;
						case '2':


							cout << "Deleting a Flight" << endl;
							a.DeleteFlight();
							break;
						case '3':


							cout << "Querrying a Flight" << endl;
							a.EnquireFlight();
							break;
						case '4':


							cout << "Returning to Main Menu" << endl;
							quitFlightMenu=1;
							break;
						default:


							cout << "Invalid Flight Menu Selection" << endl;
							break;
					}
				}
				break;
			case '2':
                                


				while (quitPassengerMenu != 1)
				{ Passenger p;
                                  
				showPassengerMenu();
                                        char z;
 	                                cin>>z;
					switch (z)
					{
						case '1':


							cout << "New Reservation" << endl;
							p.Check();
							break;
						case '2':


							cout << "Cancellation" << endl;
							p.Cancel();
							break;
						case '3':


							cout << "Viewing an existing reservation" << endl;
							p.ViewRegistration();
							break;
						case '4':


							cout << "Returning to Main Menu" << endl;
							quitPassengerMenu=1;
							break;
						default:


							cout << "Invalid Passenger Menu Selection" << endl;
							break;

					}
				}
				break;
			case '3':


				cout << "Thank you for visiting Indian Private Airlines" << endl;
				//exit (1);
				quitMainMenu=1;
				break;
			default:


				cout << "Invalid selection" << endl;
				break;
		}
	}
}

};





class Flight
{
		char flight_id[4];
		int capacity_economy;
		int capacity_firstclass;

		int e_fare;
		int f_fare;
        public:
		int date;
		int mon;
		char source[25];
		char destination[25];


					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");
					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;
	int count;


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;
					int 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");
						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)
									
									{
									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.menu();

getch();

}

No. You obviously didn't bother to read the link I posted.

Sorry,,, Hope i didn't do much damage,,,

It's more that you reduce the number of people who have time to help you. There's no real damage, except to how quickly you can learn the things that you need to in order to solve your problem.

Does this make it any better ?:|

Not really, did you read and understand the link that WaltP posted? For example, I'll re-post a section of your code in a way that might mean people have at least some hope of understanding it and, therefore answering your question:

class Flight
{
    char flight_id[4];
    int capacity_economy;
    int capacity_firstclass;
    int e_fare;
    int f_fare;

public:
    int date;
    int mon;
    char source[25];
    char destination[25];
    
    void EnterDetails();  /**< Only method declarations here (unless your function is REALLY short) */
    void AddFlight();     /**< Another function declaration */

}

/* Now the function definition */
void Flight::EnterDetails()
{    /**< There should NEVER be anything on the same line as this brace! (e.g. on line 233 of your code) */
    cout << "Enter Flight Id = ";
    gets( flight_id );    /**< Note the spaces inside the brackets, this helps your readers */

    /* There are carriage-returns between the separate user inputs, helping the reader to see
       where separate parts of the logic begin and end */
    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;
}

Note that the "tabs" in the version that I've made here are only 4 spaces, yours are more like 8 or 10, and sometimes you have two of them, sometimes none.

If you copy and paste from whatever you edit your code in and it doesn't look like this, then take a couple of minutes to MAKE IT look like this. It will save you a lot of time in the end. Also, you never know, sometimes you can find a mistake that you didn't notice before :)

commented: Thanks again +1

In my opinion the Menu class should deal with menus. I would recommend you declare an Airline class to deal with things like searching for a Flight, adding/deleting a flight, etc. The Airline class should also be able to display a Flight, though that may be as simple as having the Flight display itself. A Flight should also be able to display the seating, describe the fees, etc.

When using files, if you open a file, make a change to anything within the file, and then want to write those changes back to the file you (usually) have to rewrite the whole file. To do that, read the whole file (if you can) into your program, once. Then search the copy of the file from within the program making changes as desired. Then, when done with the file contents, write the entire "file" (containing changes/corrections, etc) back to long term memory.

It's more that you reduce the number of people who have time to help you. There's no real damage, except to how quickly you can learn the things that you need to in order to solve your problem.

Not really, did you read and understand the link that WaltP posted? For example, I'll re-post a section of your code in a way that might mean people have at least some hope of understanding it and, therefore answering your question:

class Flight
{
    char flight_id[4];
    int capacity_economy;
    int capacity_firstclass;
    int e_fare;
    int f_fare;

public:
    int date;
    int mon;
    char source[25];
    char destination[25];
    
    void EnterDetails();  /**< Only method declarations here (unless your function is REALLY short) */
    void AddFlight();     /**< Another function declaration */

}

/* Now the function definition */
void Flight::EnterDetails()
{    /**< There should NEVER be anything on the same line as this brace! (e.g. on line 233 of your code) */
    cout << "Enter Flight Id = ";
    gets( flight_id );    /**< Note the spaces inside the brackets, this helps your readers */

    /* There are carriage-returns between the separate user inputs, helping the reader to see
       where separate parts of the logic begin and end */
    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;
}

Note that the "tabs" in the version that I've made here are only 4 spaces, yours are more like 8 or 10, and sometimes you have two of them, sometimes none.

If you copy and paste from whatever you edit your code in and it doesn't look like this, then take a couple of minutes to MAKE IT look like this. It will save you a lot of time in the end. Also, you never know, sometimes you can find a mistake that you didn't notice before :)

Okay,, so I applied the proper indentation ( really hope its proper now:sad: ),,a Random Id generator and tweaked few things,, no errors or warnings on compiling,, But Still AddFlight() Functions doesn't responds,, it does nothing,, please help if you can in any way,, really appreciate your time and efforts..
My edited code:

#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <process.h>
#include <stdlib.h>

class Flight
{
    char flight_id[4];
    int capacity_economy;
    int capacity_firstclass;

  public:
    int date;
    int mon;
    char source[25];
    char destination[25];
    int e_fare;
    int f_fare;
    void EnterDetails();
    void AddFlight();
    void EnquireFlight();
    void DeleteFlight();
};

void Flight::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 Flight::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 Flight::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 Flight::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" );
    rename( "temp.txt","Flight Records.txt" );
    }


class Passenger
{


    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 RID;
    char confirm;



  public:
    void MakeReservation();
    void See();
    void ViewRegistration();
    void Cancel();
    void Check();

};

void Passenger::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 Passenger::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 Passenger::ViewRegistration()
{
    Passenger p1;
    int PID;
    ifstream fin( "Reservations.txt" );


    if( !fin )
    {
    cout << "File doesn't exists ";
    exit ( 0 );
    }

    cout << "Please enter your registration ID";
    cin >> PID;

    while( !fin.eof() )
    {
    fin.read( ( char* )&p1,sizeof( p1 ) );

    if( p1.RID==PID )
    {
    cout << endl << "Registration Details: ";
    p1.See();
    }
    else
    cout << "Sorry, no such registration exists ";
    }

    fin.close();
}


void Passenger::Cancel()
{
    Passenger p1;
    int PID;
    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 >> PID;

    while( !fin.eof() )
    {
    fin.read( ( char* )&p1,sizeof( p1 ) );

    if( p1.RID==PID )
    {
    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" );
    rename( "temp.txt","Reservations.txt" );
}


void Passenger::Check()
{   int RID;
    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)
    {
    cout << "Available Flights = ";

    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<<"Do you want to confirm the registration (y/n)?";
    if( confirm=='y')
    {
    fout.write((char*)&p1,sizeof(p1));
    RID=rand();
    fout<<RID;


    cout<<"Registration Successful!, Note the following ID and please contact 0581-2456781 to proceed with payment ";

    cout<<endl<<"ID: ";
    cout<<RID;

    cout<<endl<<"Please review registration details = ";
    p1.See();

    }
    }
    else
    cout<<"Sorry, no such flight is available at the moment";

    }

    fin.close();
    fout.close();
}

class mainmenu
{ int x,y,z;

public:

void menu();

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]: ";

}

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]: ";

}

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]: ";

}

};

void mainmenu::menu()
{
    char x;

    int quitMainMenu=0;
    int quitFlightMenu;
    int quitPassengerMenu;
    Flight a;
    Passenger p;
    while (quitMainMenu != 1)
    {
    showMainMenu();
    cin>>x;

    quitFlightMenu=0;
    quitPassengerMenu=0;

      switch (x)
      {
	case '1':


	while (quitFlightMenu != 1)
	{
	  showFlightMenu();
	  char y;
	  cin>>y;

	  switch (y)
	  {
	  case '1':


	  cout << "Adding a new Flight" << endl;
	  a.AddFlight();
	  break;

	  case '2':


	  cout << "Deleting a Flight" << endl;
	  a.DeleteFlight();
	  break;

	  case '3':


	  cout << "Querrying a Flight" << endl;
	  a.EnquireFlight();
	  break;

	  case '4':


	  cout << "Returning to Main Menu" << endl;
	  quitFlightMenu=1;
	  break;

	  default:

	  cout << "Invalid Flight Menu Selection" << endl;
	  break;

	}
      }
      break;
	  case '2':

	  while (quitPassengerMenu != 1)
	  {

	    showPassengerMenu();
	    char z;
	    cin>>z;

	      switch (z)
	      {
	  case '1':

	  cout << "New Reservation" << endl;
	  p.Check();
	  break;

	  case '2':

	  cout << "Cancellation" << endl;
	  p.Cancel();
	  break;

	  case '3':

	  cout << "Viewing an existing reservation" << endl;
	  p.ViewRegistration();
	  break;

	  case '4':

	  cout << "Returning to Main Menu" << endl;
	  quitPassengerMenu=1;
	  break;

	  default:

	  cout << "Invalid Passenger Menu Selection" << endl;
	  break;

	     }
	 }
	  break;

	case '3':

	cout << "Thank you for visiting Indian Private Airlines" << endl;
	//exit (1);
	quitMainMenu=1;
	break;

	default:

	cout << "Invalid selection" << endl;
	break;
	}
    }

}


void main()
{
    clrscr();

    mainmenu m1;

    m1.title();

    m1.menu();

    getch();

}

Okay,, so I applied the proper indentation ( really hope its proper now:sad: )

Almost, it looks like you got a bit bored of indenting in the middle, but it's getting there ;)

Still AddFlight() Functions doesn't responds,, it does nothing

This part is your problem in that respect

char ch;
ofstream fout("Flight Records.txt",ios::app);
 
while( ch=='y' )
{

What value would you expect ch to have the first time the condition in the while loop is evaluated? You could use a do... while loop instead.

You also don't need an instance of an object to use that object's member functions inside another of its member functions. So, for example, in AddFlight() you can do this:

void Flight::AddFlight()
{
    char ch = 'y';   // Give this an initial value, so that the while loop gets executed at least once
    ofstream fout( "Flight Records.txt", ios::app );
 
    while( ch=='y' )
    {
	EnterDetails();   // You can call this like a normal function, since we're inside the Flight class
	fout.write( ( char* )this, sizeof( Flight ) );    // 'this' is a special key word which is a pointer to the current object
 
	cout << "Want to enter more records ? (y/n)" ;
	cin >> ch;
    }

    fout.close();
}

This is a different case to the problem you originally had, where you were trying to call a member function of the Flight class from inside the mainmenu class.

Almost, it looks like you got a bit bored of indenting in the middle, but it's getting there ;)


This part is your problem in that respect

char ch;
ofstream fout("Flight Records.txt",ios::app);
 
while( ch=='y' )
{

What value would you expect ch to have the first time the condition in the while loop is evaluated? You could use a do... while loop instead.

You also don't need an instance of an object to use that object's member functions inside another of its member functions. So, for example, in AddFlight() you can do this:

void Flight::AddFlight()
{
    char ch = 'y';   // Give this an initial value, so that the while loop gets executed at least once
    ofstream fout( "Flight Records.txt", ios::app );
 
    while( ch=='y' )
    {
	EnterDetails();   // You can call this like a normal function, since we're inside the Flight class
	fout.write( ( char* )this, sizeof( Flight ) );    // 'this' is a special key word which is a pointer to the current object
 
	cout << "Want to enter more records ? (y/n)" ;
	cin >> ch;
    }

    fout.close();
}

This is a different case to the problem you originally had, where you were trying to call a member function of the Flight class from inside the mainmenu class.

Hey Thanks lot!! :icon_cheesygrin: IT WORKS!!! :twisted: ... There was no chance i would have completed this without your help... Seriously sir you are the most awesome/friendly guy i met on Daniweb who knows his thing..
Thanks a lot again,, reeeally appreciated your help and effort:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.