Description
CONCEPT: FORWARD DECLARATIONS
For this project Forward Declarations of classes are required since classes are co-dependent upon each other. A practical example of this co-dependency would be if a Doctor object contains a list of Patient objects, and each Patient object contains a list of Doctor objects. In this situation, do we declare the Doctor or the Patient first? The solution is to use Forward Declarations in each file as follows:
// Doctor.h file
#include “Patient.h” // include Patient.h
class Patient; // forward declaration of the Patient class class Doctor {
Patient *patient_list; // array of Patient objects
};
// end of Doctor.h file
// Patient.h file
#include “Doctor.h” // include Doctor.h class Doctor; // forward declaration of Doctor class class Patient {
Doctor *doctor_list; // array of Doctor objects
};
// end of Patient.h file
CONCEPT: AGGREGATIONS AND INHERITANCE
This project will associate classes via Aggregations and Inheritance.
Within the scope of this project class aggregations will not require the big three since each object must have independent lifetimes and each object should not be cloned. This includes the majority of class types including Airline, Airport, Flight, Person and Pilot. Practically speaking Flights would be a logical candidate for cloning, but this is not a requirement for this project.
Furthermore, some use of inheritance/polymorphism will be required with the Passenger and Pilot classes since they are both of type Person.
CLASS ASSOCIATIONS
This project implements part of a simple flight reservation system using a variety of classes associated via aggregation and inheritance.
The is a simple list of classes and their data member associations (aggregation or inheritance) with other classes. Keep these associations in mind when considering dependencies and function requirements. Airline
Airport
MyArray Flight* (arrivals)
MyArray Flight* (departures)
Person
MyArray Flight* (flights)
Passenger (inherits from Person)
Pilot (inherits from Person)
Flight
Airline
Airport (source)
Airport (destination)
Pilot
MyArray Person* (passengers)
PROJECT PHASES
This is the probably the most complex program you have attempted to develop thus far. For this reason, the project has been divided into five implementation phases. Five Phase_#.cpp files (1 to 5) have been provided to test your project at each phase of development.
Your project will run with only one Phase_#.cpp file at a time which is decided by editing your makefile.
Phase_1.cpp through Phase_4.cpp files must not be edited in your project submission to receive credit. Phase_5.cpp must be edited to match the client interface specifications of the fifth phase.
You should read this entire document (especially class specifications) before starting the project.
Watch the video to help you understand how to proceed and what is required.
Phase 1: Implement the project skeleton
- Make sure your Template Homework MyArray container compiles as is. If not fix it first.
Copy the template MyArray class code (nothing else) into a MyArray.h file.
- Create empty .h and .cpp files for all of the files listed above.
- Only add the following required code for each file (review the class descriptions): include statements
- header guards (#ifndef, def, #endif code)
- forward declarations if required
- Basic class code including:
- All data members except for MyArray objects
- Default constructor declarations in .h files, definitions in .cpp files (no other functions)
- Duplicate the downloaded makefile for easy copy/paste editing later on.
- It may help to remove any references to Flight in the makefile until you get all other files working.
- Repetitively compile and debug until the skeleton of the program is functioning.
Do not advance until Phase 1 compiles perfectly.
Phase 2: Constructors and Output
- Modify the makefile to run cpp instead of Phase_1.cpp.
- Comment out and uncomment parts of cpp as you work through this phase.
- Complete all constructor functions with exception to MyArray object content for these classes:
Airline, Airport, Person, Pilot, Passenger, Flight
- Complete getName accessor function declarations and definitions for the following classes:
Airline, Airport, Pilot, Passenger
- Complete the overloaded << operator functions for the following classes: Airport, Passenger, Pilot, Flight
Do not advance until Phase 2 compiles perfectly.
Phase 3: Accessors and Mutators
- Modify the makefile to run cpp instead of Phase_2.cpp.
- Add the remaining specified set and get (not add/remove) functions for the following classes:
Airline, Airport, Flight, Passenger, Person, Pilot
- For the moment avoid any code which requires add/remove functions for MyArray objects.
Do not advance until Phase 3 compiles perfectly.
Phase 4: MyArray Objects and Functions
- Modify the makefile to run cpp instead of Phase_3.cpp.
- Add MyArray objects as specified to the following classes:
Airport, Person, Flight
- Add addArrival, removeArrival, addDeparture, removeDeparture functions to class Airport.
Update the Flight multi-parameter constructor to work with these new functions.
- Add Pilot addFlight and removeFlight
Add Passenger addFlight and removeFlight functions.
Add Flight addPassenger and removePassenger functions
Add Flight getPassenger, listPassengers and getNumPassengers functions Note that all of these functions and similar and are dependent upon each other.
You need to update all of these functions progressively and simultaneously while testing for compiler errors.
- Add any remaining class functions (check all files and class specifications).
Do not advance until Phase 4 compiles perfectly.
Phase 5: Client Interface
The client interface is a program that uses all classes of your project to build a flight reservation system.
- Modify the makefile to run cpp instead of Phase_4.cpp.
- Modify cpp to create a flight reservation client interface.
See the Client Interface description at the end of this document (last two pages).
CLASS SPECIFICATIONS
Class Airline
Data member:
name (string): name of the airline
Functions:
- default constructor
- one parameter constructor
- name mutator
- name accessor
Class Airport
Data member:
name (string): name of the airport
symbol (string): 3 letter symbol, for example John F Kennedy is JFK arrivals (MyArray): MyArray of arriving flight object pointers departures (MyArray): MyArray of departing flight object pointers
Functions:
- default constructor
- two parameter constructor
- name mutator and accessor
- symbol mutator and accessor
- addArrival
- Call whenever a flight destination is set to this airport
- Check if a flight is in arrivals If so, add flight to arrivals
- addDeparture
- Call whenever a flight source is set to this airport
- Check if a flight is in departures If so, add flight to departures
- removeArrival
- Call whenever a flight destination is no longer this airport
- Check if a flight is in the arrivals If so, remove flight from arrivals
- removeDeparture
- Call whenever a flight source is no longer this airport
- Check if a flight is in departures If so, remove flight from departures
- closeAirport
- All flights in arrivals and departures should have source/destination set to nullptr (use flight functions) j. overloaded << operator
- Print name, symbol and list arrivals and departures, if no arrivals or departures print none.
Class Person
This is an abstract class which does not require a .cpp file, only a .h file.
Data member:
name (string): name of the airline
Functions:
- default constructor – inline definition
- one parameter constructor – inline definition
- name mutator – pure virtual function (defined in derived classes)
- name accessor – pure virtual function
- addFlight – pure virtual function
- removeFlight – pure virtual function
Class Pilot
This class is derived from class Person.
Data member:
flights (MyArray): MyArray of flight object pointers
Functions:
- default constructor
- one parameter constructor
- addFlight
- Check if a flight is in flights
- If not, add flight to flights
- Set flight pilot to this pilot (use flight functions)
- removeFlight
- Check if a flight is in flights
- If so, remove flight from flights
- Set flight pilot to nullptr (use flight functions)
- overloaded << operator
- Print name and list flights
Class Passenger
This class is derived from class Person.
Data member:
flights (MyArray): MyArray of flight object pointers
Functions:
- default constructor
- one parameter constructor
- addFlight
- Check if a flight is in flights
- If not, add flight to flights
- Add passenger to flight passengers (use flight functions)
- removeFlight
- Check if a flight is in flights
- If so, remove flight from flights
- Remove passenger from flight (use flight functions)
- cancelFlights
- Remove passenger from every flight in flights (use flight functions)
- overloaded << operator
- Print passenger name and list the flights
Class Flight
Data member:
number (int): the number of the flight airline (Airline): the flight airline source (Airport): the airport the flight will depart from destination (Airport): the airport the flight will arrive at pilot (Pilot): the pilot of the flight
passengers (MyArray): MyArray of Person object pointers
Functions:
- default constructor
- multi parameter constructor
- Initialize number, airline, source, destination and pilot
- Add this flight to the source airport departures (do this after Airport class is complete)
- Add this flight to the destination airport arrivals (do this after Airport class is complete) Add this flight to the pilot flights (do this after Pilot class is complete)
- getNumber – return flight number
- getAirline – return airline pointer
- getSource – return source pointer
- getDestination – return destination pointer
- getPilot
- If pilot is nullptr return “No Pilot”
- otherwise, return pilot name as string (use pilot functions)
- getPassenger –
- given an index, return a Person object reference to a passenger in passengers
- setAirline – Airline object as parameter
- setSource – Airport object as parameter
- setDestination – Airport object as parameter
- setPilot
- Pilot object as parameter
- If replacing a pilot, remove this flight from old pilot flights Set pilot to new pilot and add flight to new pilot flights
- nullPilot – set pilot to nullptr
- nullSource – set source to nullptr
- nullDestination – set destination to nullptr
- addPassenger
- Accept a Person object by parameter.
- Check if passenger is in passengers.
- If not, add passenger to passengers and add flight to passenger flights
- removePassenger
- Accept a Person object by parameter.
- Check if passenger is in passengers.
- If so, remove passenger from passengers and remove flight from passenger flights
- listPassengers – print a list of the passengers
- getNumPassengers – return the number of passengers
- cancel
- Remove flight from source airport departures, set source to nullptr
- Remove flight from destination airport arrivals, set destination to nullptr
- Remove flight from pilot flights, set pilot to nullptr
- Remove flight from each passenger flights in passengers
- overloaded << operator
- Print number, airline, source, destination, pilot and list passengers.
CLIENT INTERFACE
Modify the Phase_5.cpp file to implement a flight reservation client interface as specified below. The provided file implements a few global containers and a read function with some data to get you started
Watch the end of project video for a walk through of the client interface.
EXPECTATIONS/ CONCERNS
The description for the client interface is somewhat vague to provide some flexibility in implementation.
When modifying objects it is extremely important to update all associated objects. For example if you delete a Flight you have to update associated MyArray objects such as source object departures, destination object arrivals, pilot object flights and passenger object flights. Always consider how all associations will be impacted when modifying data.
Above all, it is important that the interface you code is easy to read, easy to understand and bug free. It is significantly better to code less with no bugs then to code more with tons of bugs. CONTAINERS (provided In original Phase_5.cpp file)
|
Airlines Airports Passengers Pilots Flights
MENUS
MAIN MENU: |
|
| 1 Airports | (opens Airports submenu) |
| 2 Flights | (opens Flights submenu) |
| 3 Passengers | (opens Passengers submenu) |
| 4 End program
AIRPORTS SUBMENU |
(end the program) |
| 1 List Airports | (list Airports by index) |
| 2 Create Airport | (create a new Airport name and symbol) |
| 3 Delete Airport | (list Airports, select by index to delete) |
| 4 Main Menu
FLIGHTS SUBMENU |
(return to Main Menu) |
| 1 List Flights | (list Flights by index) |
| 2 Add Flight | (create a new Flight, select all data members by index) |
| 3 Delete Flight | (list Flights, select by index to delete) |
| 4 Select Flight | (list Flights and select by index to open Flight Submenu) |
| 5 Main Menu | (return to Main Menu) |
| FLIGHT SUBMENU | |
| 1 Change Pilot | (list pilots, select by index to modify pilot) |
| 2 Change Departure Airport | (list Airports, select by index to modify source airport) |
| 3 Change Arrival Airport | (list Airports, select by index to modify destination airport) |
| 4 Add Passenger | (list Passengers, select by index to add Passenger) |
| 5 Remove Passenger | (list Passengers, remove by index to remove Passenger) |
| 6 Flights Menu
PASSENGER SUBMENU |
(return to Flights Submenu) |
| 1 List Passengers | (lists all Passengers in database) |
| 2 Create Passenger | (create a new Passenger and add it to the Passengers container) |
| 3 Delete Passenger | (lists Passengers, select by index to delete) |
| 4 Main Menu | (return to Main Menu) |
FUNCTIONS
These are a number of recommended functions you should implement to support menu actions in the Phase_5.cpp file. The purpose of these functions should be relatively obvious if you examine the menus. Many of these functions access the global containers to provide a list of options for the user to select from.
listAirlines listAirports listFlights selectPilot selectSourceAirport
selectDestinationAirport addPassenger removePassenger
changeFlight (can use this to run the Flight Submenu or code it in Main) createAirport deleteAirport createPassenger
deletePassenger


