Lab Assignment #1, 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:  Arrays (multi-dimensional)

                                      Searching

                                      Recursion

                                      Arithmetic

                                      File input

 

In the pre-lab we started implementing a small travel planning assistance system (TPAS) like it was a Travelicita or an Orbitty (you know, baby versions)  In this lab we will modify the data structures from the pre-lab and add more information, we will have more ways to search, and we will change costs based on how far in advance a ticket is being reserved.  If you didnÕt implement the pre-lab then you might want to read the pre-lab assignment along with this one so that you clearly understand all the things I mention.

 

The tasks for this lab, Lab #1, will be:

 

á       Introduce the system to a new user.

á       Create one multi-dimensional array to store the flight data in and then populate the arrays with data.  (This will be all the data from the pre-lab as well as additional info)

á       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)   Update the data in the arrays – this will take the user to a submenu for doing updates

       4)   End the program

 

Each of these tasks is described in more detail below.  There are also a few simplifying assumptions for Lab #1.  Many of these simplifications will be eliminated in later labs.

 

Simplifying assumptions for Lab #1:

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)   All flights depart and arrive at Texas cities.

c)    For simplicity, the user will enter the date on which they are ÒplanningÓ their flight plans.  This could be the current date of some past or future date.  This date affects the flight cost.

 

 

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.  This screen must also ask the user to enter the ÒplanningÓ date as a day, a month, and a year.  This can be the actual date or some other date for testing purposes. This date is needed for cost calculations. 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.

 

á       Create one multi-dimensional array to store the flight data in and then populate the array with data.

For Lab #1, the flight data will all be stored in one multi-dimensional array called flight with twenty sets of data which are described below.  Create a multi-dimensional array to hold all the data below.  Since there are 13 pieces of data and 20 possible sets of data the array must be two-dimensional of size 13 x 20.  The pieces of data are as follows:

o       flight airline – where one character will indicate a specific airline.  You must specify in your comments and in your information for the user what the meaningful character abbreviations are.  Ex: ÔJÕ for Jet Airways, ÔSÕ for Air Sahara, ÔIÕ for Indian Airlines, etc. as YOU define it. [Remember that a character is just a little tiny integer when thinking about the data type of the array.]

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:  flight number[n] will be the number that goes with  flight airline[n].

o       flight departure time – an integer.  flight departure time[n] is the departure time for the flight [n] given by the associated airline and flight number.  The departure time must 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.

o       flight arrival time – an integer with time stored as military time.

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 flight [n].

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

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

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

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

o       flight date year – an int of four digits (2006 not 06).  Numeric value for year.

o       flight departure city – an integer code from the list below representing Texas airports.

o       flight arrival city – an integer code from the list below representing Texas airports.

 

                              Texas airport                             Airport code

                              Dallas Fort Worth IntÕl         10

                              Dallas Love Field                    5

                              FW Alliance Airport              7

                              Houston International           20

                              Houston Hobby                       15

                              Austin                                           30

                              San Antonio                              40

                              Galveston                                   17

                              Lubbock                                      50

                              Abilene                                        60

                              El Paso                                         70

                              Brownsville                               80

                              Texarkana                                  90

                             

 

Given the amount of data to be entered now, the program will read the input from a file called Òlab1input.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 to the list of data above:

 

airline number deptime arrtime stops lowcoach lowbusi lowfirst day month year depcity arrcity

 

So as an example, an American Airlines flight number 232 from DFW to Houston IntÕl nonstop on Oct. 1, 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:

 

A 232 1150 1302 0 25 150 325 1 10 2006 10 20

 

Your program must create a file variable and link it to the file Òlab1input.datÓ and open the file for reading.  Then the program must read the data from the input file into the multi-dimensional flight array of size 13x20 as specified above.  This means that flight[0][n] will be the airline code for the nth flight in the list, flight[1][n] will be the flight number for the nth flight in the list,  flight[2][n] will be the departure time, etc. up to flight[12][n] which will be the arrival city for the  nth flight. 

 

To read the data from the file, your program should read the thirteen elements from each line and store them into the 13 nth elements in the array.  Make sure to check for the validity of

the airline code character  (donÕt forget to supply a list of abbreviations for them),

the times (remember that the time must be stored as military time so you must either make your user enter military time or convert the AM/PM time they give to military time),

the number of stops (>= 0),

the costs (>=0),

the day, month, and year, and

the city airport codes (must be from list).

 

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.  If the count value is larger than the actual amount of data your program will crash.  In this lab you do not need to check the lines of data against the count.  If count is smaller than the actual number of lines of data, ignore the remaining lines of data.

 

á       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 – user gives a preferred time and date

iv-  Search for a flight by arrival schedule  – user gives a preferred 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- Update flight data

viii-       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.  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 ÒplanningÓ date entered by the user on the welcome screen 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. 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 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 – This search will probably give ties.  Print all the values that match the search.

 

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 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 character.  Once the correct flight is determined save its [index] 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       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 within Texas.  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:

Two dimensional integer array for recording flight information

 

The program should use the following control structures:

Function calls to perform tasks

File input

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:

               structs

               linked lists

               global variables

               exit

               break (other than in a switch)

               continue

               strings

               pointers or pass by reference (except for arrays)

               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:   (53 %)

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 (10 points)

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

Correct manipulation of the multi-dimensional arrays  (8 points)

Correct use of required control structures (8 points)

Correct use of input file (9 points)

Proper implementation of input error checking (9 points)

Output:         (47%)

               User clearly understands what is being requested for input (2 points)

       Correct implementation of menus  (5 points)

               Search (find) tasks perform correctly (9 points)

               Recursive cost function works 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 structs, strings, linked lists, pointers, and/or pointer notation 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.