Lab Assignment #4, CSE 1320-001 Fall 2006
Due Date: See section website for due date
(see instructions on website for how to turn this in)
Topic objectives: Classes
Objects
Methods
C++
We are now going to modify the implementation of our small travel planning assistance system (TPAS) -Travelicita or Orbitty (or whatever name you might prefer) In this lab we will modify the data structures from the previous labs and begin the change to an object oriented paradigm, we will continue to search, we will do more sophisticated updates and we will still change costs based on how far in advance a ticket is being reserved.
The tasks for this lab, Lab #4, are:
¬ Introduce the system to a new user.
¬ Develop a class type to record all the flight data, constructor functions, destructor functions, accessor functions, and mutator functions about any one airline flight. (This will be all the data from the previous labs)
¬ Create one array of objects to store the flight data in and then populate the array with data.
¬ Create and display a menu of the following choices for the user.
1) Using the data in the arrays, search for flights by a variety of criteria
2) Calculate costs based on reservation date vs. flight date and one-way vs. round-trip
3) Sort the objects in the array
4) Update the data in the arrays – this will take the user to a submenu for doing updates
5) End the program
Each of these tasks is described in more detail below. There are also a few simplifying assumptions for Lab #4. Many of these simplifications will be eliminated in later labs.
Simplifying assumptions for Lab 4:
a) All flights have a base cost for a one-way ticket and a base cost for a round-trip ticket and then the actual one-way or round-trip cost is calculated with a recursive function based on how far in advance the ticket is reserved.
b) This lab is basically Lab 2 with objects and methods plus some of the extra functionality from Lab 3. This will cause a good bit of the program to be rearranged and rewritten.
Task Descriptions:
¬ Introduce the system to a new user.
For this task your system must provide an introduction/welcome screen to the user. The screen should briefly describe what the system will do. You may have the welcome screen stay up for a fixed period of time or you may let the user press a key to continue on with the program. Make sure you tell the user what to do if you want them to press a key. Do NOT have the user enter a planning date.
¬ Develop a class type to record all the flight data about any one airline flight.
For Lab #4 all the private data for one flight must be stored in a single object. You must declare a class type to hold this data. The class type you create should be placed in a header file for the program. The class must contain data and methods. Some of your existing functions may become methods and some may still be global functions requiring regular function prototypes.
All objects (variables) instantiated (created) from this class (struct) type must be declared inside of the main function of the program. The object must hold the following data in the following form. Note that some elements may now be stored differently than they were previously.
o flight airline – a string that holds the name of the airline. Your string can be stored in a fixed size character array of at least 20 characters OR you may use a character pointer and dynamically allocate memory for the string. Make sure you always store a valid string in the 20 char array even if the original string read from the file is longer. The airline name will always be one word typed without spaces in the file. Functions that use this string should declare a char * variable to manipulate the string with.
o flight number – an integer that gives a specific number for a flight. Together a flight airline and a flight number will designate a particular flight.
o flight departure time – an integer. flight departure time is the departure time for the flight given by the associated airline and flight number. The departure time may be stored as a military time (a 24 hour clock instead of 12 hours AM and 12 hours PM) Ex: 10:00am would be 1000 military time while 10:15pm would be 2215 military time. Time can be stored as part of another struct if desired.
o flight arrival time – an integer with time stored as 12 hour am/pm time or as hours and minutes or as military time. Can be part of another struct if desired.
o flight number of stops – a short int. A direct flight has 0 stops.
o flight layovers – a new class type object containing the 3 letter airport code of the layover city, a flag representing whether the traveler is physically changing planes or not, a length of time representing how long the layover will be given as a four digit number of hours and minutes hhmm. All flight data objects will have an array of size four of layover objects. If the original flight has 0 number of stops all the data in this layover array will be 0s. If the original flight has 1 or more stops there will be a data in one or more layover objects in the array, one for each stop.
o flight lowest coach seat – a float or double giving the lowest full-fare round-trip price for any coach seat on the flight.
o flight lowest Business seat – a float or double giving the lowest full-fare round-trip price for any Business class seat on the flight.
o flight lowest First class seat – a float or double giving the lowest full-fare round-trip price for any First class seat on the flight.
o flight date day – an int. Day of the month. Day must be valid for associated month (i.e. the flight canÕt occur on February 31st.) Can be part of another struct if desired.
o flight date month – an int. Numeric value for month with 1 = January, 2 = Feb. through 12 = Dec. 1 – 12 are the only valid values. Can be part of another struct if desired.
o flight date year – an int of four digits (2006 not 06). Numeric value for year. Can be part of another struct if desired.
o flight departure city – a three character string representing the international designation for the desired airport (ex. DFW is Dallas Fort Worth, MAA is the Chennai, India airport)
o flight arrival city – a three character string representing the international designation for the desired airport
o flight seat preference – a single character representing aisle (a), window (w), middle (m), or none (n). Any other character is treated as none.
o flight meal preference– a single character representing vegetarian (v), low-fat (f), low-salt (s), vegan (g), kosher (k), special (p), or regular (r). Any other character is treated as regular.
o flight passenger – a string which will contain the passengers name once a flight is selected.
o flight seat level – an enumerated type of either COACH, BUSINESS, or FIRST – Note that this data will be added to the struct after the user selects a flight.
o flight seat amenities – a union containing three possible values:
if flight seat level is COACH then the union contains a bit field representing preference for special headphones(2), regular headphones (1) or none (0)
if flight seat level is BUSINESS then the union contains a float representing the dollar amount paid to upgrade this seat from coach if that was done or a zero if the seat was purchased directly as business class
if flight seat level is FIRST then the union contains a char representing preference for alcoholic (A) or non-alcoholic (N) beverages.
o flight link – a flight structure pointer to another flight. Should be initialized to NULL.
¬ Create one array of the class type above to store the flight data in and then populate the array with data from a file.
For Lab #4, the flight data will all be stored in one array of objects with at least fifty objects as are described above. Declare an array to hold all the flight data.
The program will read the input from a file called Òlab3input.datÓ. This is the same data file used for Lab #3. See the Lab #3 assignment for the file format. Read either all the data in the file or the first 50 flights whichever comes first. Keep a count of the total number of flights stored in the array.
As the data is going to be stored in each object, make sure to check for the validity of
the airline name (a valid string has to be stored in the size array you have declared),
the number of stops (>= 0),
the costs (>=0),
the day, month, and year, and
the city airport codes (must be real 3 letter airport codes).
You must use mutator functions in the object to verify the validity of each input and to store either a valid input or a default value if the input is not valid. Give the user a message for each default value that is used.
When the program has read in the flights from the file, print out all the flight data in an easily readable form, ex. use a table with headings, or columns with headings or rows with labels. The data to be printed must be acquired through the use of accessor functions.
¬ Create and display a menu of choices for the user.
Once all the data is read into the array your program should give the user a menu with the following choices: (use any number scheme you wish)
i- Search for a one-way flight by lowest cost or by lowest cost in a certain class
ii- Search for a round-trip flight by lowest cost or by lowest cost in a certain class
iii- Search for a flight by departure schedule to a given city – user gives airport, time and date
iv- Search for a flight by number of stops – user gives a preferred number of stops
v- Sort all flight data
vi-Update flight data
vii- Add a flight to the list
vii- Delete a flight from the list
ix- End the program
All of the search options should call search functions that perform linear search on the array of data. When the search is complete your program should print the search result(s) and then show the user the menu again. In case of ties, print all results. Note that the searches now must do string comparisons for airport codes and airlines when those are needed. See search, update, add and delete descriptions from Lab #3.
The data to be compared and returned must be acquired through the use of accessor functions.
When you print the search results, make sure to print all of the data for the flight(s) matching the search criteria.
The sort option should take the user to a second screen to allow them to sort all the flight information based on various criteria. The user should be able to sort the flight data based on
o flight departure city – alphabetically
o flight arrival city - alphabetically
o flight lowest cost seat (any class)
o flight date day
o flight airline
After each sort is performed, print all of the flights in the array of objects in the new sorted order.
The update option should take the user to a second screen to allow them to update information in the arrays. This screen should ask for an airline flight number from the user and search for that flight. If multiple flights with that number are found, ask the user for the airline name. Once the correct flight is determined save the [index] of the object containing the flight and give the user a menu of the following options:
o Change flight departure time[index]
o Change flight arrival time[index]
o Change flight number of stops[index]
o Change flight lowest cost seat[index]
o Change flight lowest coach seat [index]
o Change flight lowest Business seat [index]
o Change flight lowest First class seat [index]
o Change flight date day[index]
o Change flight date month [index]
o Change flight date year[index]
o Change flight departure city [index].
o Change flight arrival city [index]
o Change flight seat preference [index]
o Change flight meal preference [index]
o Change flight passenger
o Change flight amenities
o Return to main menu
For any change the user wishes to make, use the accessor and mutator functions to do the same error checking as in the original data entry section. After each change is made, print all of the flight info for flight[index].
When the user chooses ÒEnd the programÓ from the main menu, print a concluding message and then gracefully end the program.
In addition to the task functionality your program must be contained in multiple program files. Specifically you must have:
at least one header file for each class type definition containing the description of the class and its public and private data and methods,
for each class, you must define the methods for that class either with the class or in a second file,
a file containing just your main routine;
and one or more files containing the remainder of your functions.
These files must be linked together with #include statements and must only be compiled once.
Input data file:
The input file is on the class website for you to use. You may use a subset of this file to test with if desired. Do not change the format of the file.
Implementation requirements:
The program should use the following data structures:
A class type to contain all the data and functions for one airline flight
An array of objects for recording flight information
The program should use the following control structures:
Function calls to provide data access and data change in the class
Global (file) scope functions to perform other tasks such as sorting
Input and output handled with streams and stream functions from C++
The program should use the following file structure:
One file for each class specification (.h)
One file for each set of class member function definitions (.cpp)
One file with type definitions, constants and functions prototypes for file scope functions (.h)
One file with the main routine in it (.cpp)
File with main routine may have other file scope functions defined in it or
File scope functions may be defined in one or more files
Your program must control all access to the data members of the flight object. No client function or object should be able to directly change data in an object without going through a mutator member function that does error checking and/or data validation.
Your program must be implemented in a modular object-based fashion. You must have a class defined to retrieve, hold and manage all data associated with a flight. The class will also include member functions. To run your program you will have a main routine and at least one function to display the menu, at least one function for searching, and at least one function for updating. You may have more functions than this. Each of your functions must specify any parameters it uses for input in its parameter list.
Your program should have meaningful identifiers and useful comments. It should be consistently indented and should use horizontal and vertical whitespace for readability.
The program should have a program header which gives, at least, your name, the number of the lab assignment, your class and section, the assignment date, the due date, and a description of the program. If multiple files are used, each file should contain a similar header. See your instructorÕs website for SPECIFIC instructions about the program header.
Each programmer-defined function, i.e. each function you write, should have a function header similar to those used in the examples in the textbook. This header should include at least the function name, the purpose of the function, and its inputs and outputs.
The program should perform the following actions in the given order:
Print a welcome screen for the user that introduces the system
Declare and initialize the objects
Print the appropriate outputs
Let the user enter additional values until the user indicates that they are finished.
You must demonstrate ALL of the functions of your program in your output script, i.e. do all the different searches and all the different types of updates.
The program output must be recorded in a script file from OMEGA after the program has been compiled using the gpp compiler. If you do not know how to create a script file, it is your responsibility to ask the TA or OIT how to use this function. Some helpful tips are available on the class website.
The program should NOT use:
linked lists
any topic not covered in class before the lab DUE date unless approved by the instructor
See the grading scale below for other specific implementation requirements.
Grading scale:
Code: (57 %)
Program header, function headers and comments for all functions (4 points)
Modularity (division of the problem into small tasks, each one assigned to its own function and called from main() or from another function when appropriate--do not code the entire program in main!) and correct function structure as required (3 points)
Style (indentation, consistency, meaningful identifiers, lateral separation of code from line comments, etc.) (3 points)
Correct definition of class for flight data including
All needed data members (8)
Accessor functions (6)
Mutator functions with proper input error checking and validation (10)
Constructor (and destructor as needed) functions (4)
Correct use of public and private sections (4)
Correct separation into multiple files for class specification and member function definitions (4)
Correct manipulation of array of objects (3 points)
Correct use of >> and << with C++ streams to perform I/O (5 points)
Correct use of required control structures (3 points)
Output: (43%)
User clearly understands what is being requested for input (2 points)
Correct implementation of menus (5 points)
Search (find) tasks perform correctly with modifications as required (3 points)
Recursive cost function works correctly (2 points)
Sorting tasks perform correctly (3 points)
Input of data to objects performed securely and correctly (5 points)
Updates to objects performed securely and correctly (5 points)
List of inputs correctly printed (4 points)
Output gives clear information to explain the values to the user (4 points)
Output contains examples of all program functions (10 points)
Deductions:
Use of global variables will result in an overall grade of 0 (zero)
Use of the exit command will result in an overall grade of 0 (zero)
Use of linked lists will result in 50 (fifty) point deduction per use
Use of goto, continue or break (outside a switch) will result in 50 (fifty) point deduction per use
Late submission of softcopy to appropriate TA will result in an overall grade of 0 (zero) without prior instructor approval
Use of C/C++ language elements not yet discussed in class by the lab due date will result in potential deduction of points – discuss with instructor before using.