I am a novice user and am proposing to do a project on airline reservation system in C++ as a part of class. This is something I myself have proposed. I have started to design the classes and need some help.

So far I have only created 2 basic classes:

// Class: Flight
class Flight
{
public:

private:
	string flight_id;
	int capacity_economy;
	int capacity_firstclass;
	int day;
	int mon;
	string source;
	string destination;
};

// Class: Passenger
class Passenger
{
public:

private:
	string first_name;
	string last_name;
	string address1;
	string address2;
	string city;
	string state;
	int travel_day;
	int travel_month;
	string source;
	string destination;
	int seatnumber;
	string flight_id;
};

I have not yet defined the member functions. To start with I have the following questions.

The goal is to achieve the following
- add new flights, delete existing flights, view details about a flight
- make a reservation, cancel reservation, view a reservation details
- Store all data in flat files (not in any database)

Questions:
- Do I need to create any other class to keep track of different flights or I should keep creating new instances of the Flight class and track it in my main program?
- Any suggestions/pointers in the direction to proceed, I mean any helper classes I need to use that may make programming this project easier?

Thanks
k007

I think you're already on a good way: you've already the skeleton of a class which will contain a flight's details ...

  • Continue creating your Flight class
  • If your Flight class is ready, you could create a vector of it, that's a lot easier as you don't have to bother with dynamic memory allocation, you can also delete/add records in an easy way :) !

I think you're already on a good way: you've already the skeleton of a class which will contain a flight's details ...

  • Continue creating your Flight class
  • If your Flight class is ready, you could create a vector of it, that's a lot easier as you don't have to bother with dynamic memory allocation, you can also delete/add records in an easy way :) !

Apart from that I think that you should also have 2 Passenger Lists one for economy class and one for the Firstclass travelling passengers.

I guess you can do that with vector<Passenger>member to your Flight Class

I would declare the Passenger class before the Flight class. Then I could create an array/list of Passengers for a given Flight.

In addition, I would have a 2 dimensional array of char to represent seating chart to keep track of open seats, etc. If you are familiar with vectors, then a vector of vectors could be substituted for a 2 dimensional array. If using arrays, then using dynamic memory to declare the seating will allow you to use the same program for a Flight with an arbitrary seating pattern instead of a fixed seating chart for all Flights developed with your program.

Thanks for the responses. I created the classes with your suggestions. I am having troubles in setting up the menus for this. Here is the code I am using. There seem to be 2 problems:
1. If I give 11 as my first input, it still takes it like 1 and instead of showing invalid input it shows the menu corresponding to case 1
2. If I give the inputs correctly (as expected like 1, 2, 3 ...etc.) the program works for the first time but the next time onwards it keeps giving invalid selections. Must be some issue in the way I am using cin.get

Is there a better way to deal with this?

My code -

#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <stdlib.h>
using namespace std;

// Helper Functions
void showMainMenu(void);
void menu(void);
void printTitle(void);

// Main Program
int main()
{
	printTitle();
	menu();
}

void printTitle(void)
{
	cout << "######################################################"<< endl;
	cout << "######## WELCOME TO KT PRIVATE AIRLINES ##############"<< endl;
	cout << "######################################################"<< endl;
	cout << "                                                      "<< endl;
}
void showMainMenu(void)
{
	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(void)
{
        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(void)
{
        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(void)
{
	bool quitMainMenu=false;
	bool quitFlightMenu;
	bool quitPassengerMenu;
	while (quitMainMenu != true){
	showMainMenu();
	quitFlightMenu=false;
	quitPassengerMenu=false;
		switch (std::cin.get())
		{
			case '1':
				cin.ignore();
				
				while (quitFlightMenu != true){
				showFlightMenu();	
					switch (std::cin.get())
					{
						case '1':
							cin.ignore();
							
							cout << "Adding a new Flight" << endl;
							break;
						case '2':
							cin.ignore();
							
							cout << "Deleting a Flight" << endl;
							break;	
						case '3':
							cin.ignore();
							
							cout << "Querrying a Flight" << endl;
							break;
						case '4':
							cin.ignore();
							
							cout << "Returning to Main Menu" << endl;
							quitFlightMenu=true;
							break;
						default:
							cin.ignore();
							
							cout << "Invalid Flight Menu Selection" << endl;
							break;
					}
				}
				break;
			case '2':
				cin.ignore();
				
				while (quitPassengerMenu != true){
				showPassengerMenu();
					switch (std::cin.get())
					{
	                                        case '1':
							cin.ignore();
							
                                                   	cout << "New Reservation" << endl;
                                                        break;
                                                case '2':
							cin.ignore();
							
                                                        cout << "Cancellation" << endl;
                                                        break;
                                                case '3':
							cin.ignore();
							
                                                        cout << "Viewing an existing reservation" << endl;
                                                        break;
                                                case '4':
							cin.ignore();
							
                                                        cout << "Returning to Main Menu" << endl;
                                                        quitPassengerMenu=true;
                                                        break;
                                                default:
							cin.ignore();
							
                                                        cout << "Invalid Passenger Menu Selection" << endl;
                                                        break;

					}
				}
				break;
			case '3':
				cin.ignore();
				
				cout << "Thank you for visiting KT Private Airlines" << endl;
				//exit (1);
				quitMainMenu=true;
				break;
			default:
				cin.ignore();
				
				cout << "Invalid selection" << endl;
				break;	
		}
	}
}

Thanks
k

Firstly cin.get() only gets one character input from the input stream cin. Therefore When input is given as 11 it only takes in 1 and leaves the rest.

So I think you should do this.

int x;
cin>>x;
switch (x)
{
case 1: //Remeber that i am not using '1' as its not a character.
}

So I guess Your Problem is solved by that.

Thanks for the advice. It works for the switch case. However, when I try to create an instance of Flight class inside of the switch case I get the error about:

airlinemain.cpp:103: error: jump to case label
airlinemain.cpp:100: error: crosses initialization of ‘Flight* f’
airlinemain.cpp:112: error: jump to case label
airlinemain.cpp:100: error: crosses initialization of ‘Flight* f’
airlinemain.cpp:119: error: jump to case label

I know what this means but I would not have the information to create the Flight class instance outside of the case statement right? So how do I deal with it?.

Here is my flight class:

class Flight
{
public:
	Flight(string=NULL, int=20, int=5, string=NULL, string=NULL);
	void addFlight(string f_id);
	void deleteFlight(string f_id);
	void queryFlightWithId(string f_id);
	void qeryFlightWithSource(string from);
	void queryFlightWithDestination(string to);	
	vector<Passenger> p_economy;
	vector<Passenger> p_firstclass;
private:
	string flight_id;
	int capacity_economy;
	int capacity_firstclass;
	float cost_economy;
	float cost_firstclass;
	int booked_economy;
	int booked_firstclass;
	string source;
	string destination;
};

Here is the constructorh:

Flight::Flight(string fid, int e_capacity, int f_capacity, string startplace, string endplace)
{
	flight_id=fid;
	capacity_economy=e_capacity;
	capacity_firstclass=f_capacity;
	source=startplace;
	destination=endplace;
}

Here is the part of main where I am using switch case to create instance of Flight class.

void menu(void)
{
	bool quitMainMenu=false;
	bool quitFlightMenu;
	bool quitPassengerMenu;
	int mainmenuchoice;
	int flightmenuchoice;
	int passengermenuchoice;
							string f_source, f_dest;
							string f_id;
							int e_capacity, f_capacity;
							float e_fare, f_fare;
	while (quitMainMenu != true){
	showMainMenu();
	cin >> mainmenuchoice;
	quitFlightMenu=false;
	quitPassengerMenu=false;
		switch (mainmenuchoice)
		{
			case 1:
				cin.ignore();
				while (quitFlightMenu != true){
				showFlightMenu();	
				cin >> flightmenuchoice;
					switch (flightmenuchoice)
					{
						case 1:
							cin.ignore();
							cout << "Adding a new Flight" << endl;
							cout << "" << endl;
							cout << "########### Data collection #############" << endl;
							cout << "Enter the Source: " << endl;
							cin >> f_source;
							cout << "Enter the Destination: " << endl;
							cin >> f_dest;
							cout << "Enter Flight Id: " << endl;
							cin >> f_id;
							cout << "Enter capacity for economy class: " << endl;
							cin >> e_capacity;
							cout << "Enter capacity for first class: " << endl;
							cin >> f_capacity;
							cout << "Enter fare for economy class: " << endl;
							cin >> e_fare;
							cout << "Enter fare for first class: " << endl;
							cin >> f_fare;
							Flight *f = new Flight(f_id, e_capacity, f_capacity,f_source, f_dest); 
							cout << "" << endl;
							break;
						case 2:
							cin.ignore();
							cout << "Deleting a Flight" << endl;
							cout << " " << endl;
							cout << "Here is the list of flights: "<< endl;
							// function to list the flights from flights.txt
							cout << "Enter the flight_id of the flight to delete: ";
							// 
							break;

Thanks
K

Nevermind. I think I found what I needed to do. I needed to define the Flight *f outside of the switch case and then inside the switch case I just needed to use f=new Flight(a,b,.....)

Thanks
K

This article has been dead for over six months. Start a new discussion instead.