Lab Assignment #2, 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:  Structures

                                      Strings

                                      Pointers

                                      File input and output

 

We are continuing to implement 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 add more information, 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 #2, are:

 

¬      Introduce the system to a new user.

¬      Develop a struct type to record all the flight data about any one airline flight.   (This will be all the data from the previous labs as well as additional info)

¬      Create one array of structs 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 structs 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 #2.  Many of these simplifications will be eliminated in later labs.

 

Simplifying assumptions for Lab #2:

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.

 

 

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 struct type to record all the flight data about any one airline flight.

For Lab #2 all the data for one flight must be stored in a single struct.  You must declare a struct type to hold this data.  The struct data type you create should be placed above the function prototypes in your code.  All variables of this struct type must be declared inside of the functions of the program.  The struct must hold the following data in the following form.  Note that some elements will 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.  Make sure you always store a valid string in the 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 lowest coach seat – an integer giving the lowest full-fare round-trip price for any coach seat on the flight.

o       flight lowest Business seat – an integer giving the lowest full-fare round-trip price for any Business class seat on the flight.

o       flight lowest First class seat – an integer 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 (s), or regular (r).  Any other character is treated as regular.

 

 

¬      Create one array of the struct type above to store the flight data in and then populate the array with data from a file.

For Lab #2, the flight data will all be stored in one array of structs with at least twenty structs of data as are described above.  Declare an array to hold all the flight data. 

 

Given the amount of data to be entered now, the program will read the input from a file called Òlab2input.datÓ.  This way you will create a file of data one time and then use the same file for input on every program run.

 

The first line of the file should give a count that is the total number of flights to be entered, i.e. the number of flights whose data is given in the file.  The program should read this count from the file and make sure the count is between 15 and 20.   [Note for development: start with a smaller number of flights then increase to 15 when program is working well] If the count from the file is not between 15 and 20, write an error message to the screen and end the program.  If the count is valid, then your program must loop for count number of times (index = 0, 1, É count-1) to read and store input from the file.

 

Each line of the file will have the following data items in the following order each separated by a single space.  Note that these data items correspond exactly in order and in type to the list of data above and that there are some differences from the previous lab:

 

airline num deptime arrtime stops lowcoach lowbusi lowfirst day month year depcity arrcity seat meal

 

Note that the airline name could be longer than 20 characters.  In order to make sure that the 20 character array is not exceeded, read the airline name from the file into a longer temporary character array (maybe 50 characters).  Then use the string functions to copy a maximum of 19 characters to the 20 character array and store an end of string marker if needed in the 20 char array to make a string.

 

So as an example, an American Airlines flight number 232 from DFW to Nashville, TN (BNA) nonstop on Oct. 22, 2006 departing at 11:50am and arriving at 1:02pm with a lowest coach price of $25, a lowest Business class cost of $150, and a lowest First class price of $325 might be represented as the following line in the input file:

 

American 232 1150 1302 0 25 150 325 22 10 2006 DFW BNA a v

 

Your program must create a file variable and link it to the file Òlab2input.datÓ and open the file for reading.  Then the program must read the data from the input file into the array of structs.  Each line of data will be stored in a separate struct in the array. 

 

In this lab you must check the number of lines of data against the count.  If count is smaller than the actual number of lines of data, ignore the remaining lines of data.  If the count value is larger than the actual amount of data, stop reading input when you reach the end of the file and change the count value to correctly match the number of flights read.  If count is changed make sure to print a message to the user.

 

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).

 

When the program has read in count 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. 

 

 

¬      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 arrival schedule to a given city – user gives airport,  time and date

v-   Search for a flight by number of stops – user gives a preferred number of stops

vi-  Search for a flight by airline – user gives a preferred airline

vii- Sort all flight data

viii-Update flight data

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.  Below are descriptions of each type of search to perform.

 

Searches by cost -  including one-way lowest cost search, one-way lowest cost search by class, round-trip flight by lowest cost, and round-trip flight by lowest cost .

 

The cost searches must take three kinds of information into account; the dates, the class, and the type of flight (one-way or round-trip).  This search uses the current date and the departure date of the flight to determine how much of a discount is applied to the price based on how far in advance the plans are made. The current date is captured using the built in C time functions, time and localtime, which will be discussed in class.  This search also must adjust the costs based on whether the type of flight is one-way or round-trip.   This search can optionally restrict the search to a certain class of seats (coach, Business, or First) based on a user input. 

 

Before beginning this search, the program should ask the user if they wish to check all seats or only a certain class of seat.  If the user wishes to check only one class of seat, the program should give the user a list of choices (coach, Business, First) and then let the user choose the class to search.  If the user chooses a specific class, then only those flights are searched.  If the user chooses all seats, then all three classes of tickets are searched for every flight.  (Maybe the First class is mysteriously cheaper than coach on some flightÉ)

 

The planning date discount is calculated recursively as follows.  For each month in advance that plans are made the cost of the ticket is discounted by 10% from the previous monthÕs price.   The number of months is calculated by comparing the planning date month and year to the flight departure date month and year.  Twelve months is the maximum amount of months to discount.  If plans are made in the same month as the flight then there is no discount.

 

As an example, a round-trip coach ticket for December 23, 2006 with a full-fare price of $400 would be discounted by 10% is reserved in November giving a price of $400 – ($400 * .10) = $360.  An October reservation would get another 10% on top of the November price for a cost of $360 – ($360 * .10) = $324 and so on. 

 

The planning discount applies the same way to each class ticket.

 

The other cost adjustment is for one-way flights.  The given fares are based on a round-trip which is both to and from the destination.  If the user wants to fly only one-way the fare is less than the round-trip fare but not half and is different for each class.  For coach class, a one-way ticket is 60% of the cost of the round-trip ticket.  For Business class, a one-way ticket is 66.6% of the cost of the round-trip ticket.  For First class, a one-way ticket is 75% of the cost of the round-trip ticket.  This adjustment is applied AFTER any planning discount is applied.

 

Searches by schedule - For departure and arrival searches your program your program will now search for city first by doing string comparisons.  If flights are found to that city then the closest scheduled flight is chosen.  Your program should tell the user how the flight is chosen; e.g. the closest flight after the requested time, the closest flight prior to the requested time, the closest flight in time before or after.

 

Searches by number of stops with sorted output – This search will probably give ties.  Print all the values that match the search.  Sort these flights by least stops to greatest number of stops.  Sort alphabetically by airline within each number of stops.

 

Searches by airline – This search will probably give ties.  Print all the values that match the search.

 

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 structs 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 struct 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       Return to main menu

 

For  any change the user wishes to make, 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.

 

Input data file:

Go online and collect data for at least 15 different flights to any destination.  Include at least two international flights.  These flights must include at least three different airlines.  Use this real data as data in your file that will be the input to your program.  Include a comment in your code or your script session telling what day you collected the data and what website(s) you used for data collection.

 

Implementation requirements:

 

The program should use the following data structures:

A struct type to contain all the data for one airline flight

An array of structs for recording flight information

 

The program should use the following control structures:

Function calls to perform tasks

File input

String functions for copying and comparison

A while, do-while, or for loop to read the input data

If, if-else, or nested ifs to error check numbers and values

Nested ifs or switch to implement the menu options and one-way costs

A recursive function to implement planning discounts

 

Your program must be implemented in a modular fashion.  You must have a main routine and at least one function for input, 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:

Declare and initialize the variables

Print a welcome screen for the user that introduces the system

Get the needed input values

Print the appropriate outputs

Let the user enter additional values until the user indicates that they are finished.

 

Your program must be run with the real data you collect above as described in the input data section.  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 gcc 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

               global variables

               exit

               break (other than in a switch)

               continue

               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              (5 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 (6 points)

Style (indentation, consistency, meaningful identifiers, lateral separation of code from line comments, etc.)  (4 points)

Correct manipulation of the struct and array of structs  (12 points)

Correct use of required control structures (4 points)

Correct use of required string functions (4 points)

Correct use of char * pointers to manipulate strings (5 points)

Correct use of the time functions (2 points)

Correct use of input file (6 points)

Proper implementation of input error checking (9 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 (9 points)

Updates to arrays performed correctly (4 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 language elements not yet discussed in class by the lab due date will result in potential deduction of points – discuss with instructor before using.