Lab Assignment # 3, CSE 1320 Section 501, Spring 2005

 

Due Date:         Section 501 Ð Thursday, April 7th, 5:30 pm

 (see instructions on website for how to turn this in)

 

Topic objectives:       Recursion

                                        Structs, enum and unions

                                        Static variables

                                        File input with scanf

                                        (Plus all the stuff youÕve already done)

 

OK, Spring Break is at hand so you have been trying out your vacation planning.  After taking a vacation based on your planning, you are ready to upgrade your planning system for the summer vacation planning. 

 

Your first upgrade will be to create structs that can hold all the data for one vacation in a single place.  With this struct type, you can then create an array of structs and read the input vacation data from a file into the array of structs. 

 

The struct must hold the following pieces of data:

a.       A pointer to the name of the destination

b.       Transportation code

c.        Transportation cost

d.       Transportation details string

e.        Accommodation code

f.         Accommodation cost

g.       Accommodation details string

h.       Average cost of one meal

i.         Number of nights

j.         Departure date in dd mm yyyy format

k.       Return date

l.         Average daily cost

m.     Total vacation cost

 

You program must declare an array of ten of these structs.  The program must then read in data from a file.  The data in the file will be one piece of data per line with the very first line of the file indicating the number of vacations to be read.  Following that number the next line contains the string giving the destination of the first vacation.  The file will hold the value a. Ð j. for each vacation.  Your program will read the data in the file and store it in the array of structs.

 

Once the data is read in, your program should calculate average daily cost, total cost and return date for each vacation and store that data in the appropriate member of the structs.  Your program should then print a vacation itinerary for each vacation like you did for Lab #2.  You should modify your print function from Lab #2 to work with the array of structs.

 

Now you will extend the ability of your program in the following ways.  The following three choices should be presented to the user in a menu format along with a choice to end the program.  The program should let the user continue to choose one of these options until the user chooses to end the program.

 

1)       Print a list of vacation destinations for the user and let them find out the cost of combining two vacations, i.e. if the user chooses vacations 1 and 3, then give them a total cost of vacation 1 cost plus vacation 3 cost minus the cheaper of the two transportation costs.

Combined cost of vacations a and b =

Total cost vacation a +

Total cost vacation b -

Minimum ((Transportation cost of a / 2) or

                    (Transportation cost of b / 2))

2)       Allow the user to enter a dollar amount and then use linear search to go through the vacation struct array and print out for the user all the vacations that fall under that amount. 

3)       Allow the user to choose a vacation and then enter a dollar amount and recursively decrease the number of days of the vacation until the total cost is below the entered dollar amount or until days equals zero.  Tell the user the number of days that would be possible for that vacation within the given dollar amount.  Remember that when you delete days from the vacation you are only deleting accommodation and meal costs not transportation costs.  Ex:  Vacation 2 (10 days) from the data set would have a total cost of $448.12 + 10 * ( $72.00 + (3 * $12.00)) = $1528.12 . If the user entered $1000 for their dollar amount, the program should first find the cost of a 9 day vacation with the same costs, then an 8 day, then a 7 day and so on until at 5 days the program finds a cost of $988.12 which is less than the given limit.  The program would then print out 5 days and the 5-day vacation cost to the user.

 

When the user chooses to end the program, print a concluding message and then end.

 

Implementation requirements:

The program should use the following data structures:

Array of structs for input info

Dynamic space allocation for strings for destinations

Array of pointers to strings (character arrays) or dynamic arrays for other strings

 

The program should use the following control structures:

Function calls to perform the tasks

A loop to read data, perform calculations and output for each vacation, and allow user to choose from the menu of options

Recursive algorithm for calculating option 3

Linear search for option 2

The program should NOT use the following control structures:

breaks outside of switch structures

continues

gotos

exits

 

The program should be implemented as a set of functions.

 

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 data from the keyboard

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

Print the appropriate outputs

 

The program should have a program header which gives, at least, your name, an email address where you can easily be contacted, 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. 

 

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.

 

This program must be run with three different sets of data.  The first data set (data set 1) should use the values given below.  You must also create two additional data sets and run your program with them as well.  You may run it three times within a single execution or you may execute the program two different times with one repeat within a single execution so that you have a total of three different data sets.  The sample data sets that you create must meet the guidelines given in the problem definition.

 

The program output must be recorded in a script file from OMEGA using the gcc compiler.  If you do not know how to create a script file after reviewing the instructions on the class website, it is your responsibility to ask the TA or OIT how to use this function.   

 

Sample input values for data set 1:    

Vac

Trans. type

Trans cost

Accom. type

Acc cost

Avg meal $

#

nite

Destination

Trans info

Acc info

Depart date

1

car

40.00

hotel

120.00

35.00

10

Austin

Personal car

Hyatt UT

3/11/05

2

plane

448.12

B&B

72.00

12.00

8

NYC, NY

Dep. AA 1347/ Ret. AA 1222

Big Apple Bed & Breakfast

3/12/05

 

3

bus

99.99

rental house

150.00

9.50

9

Vail , CO

Trailways 38 both ways

Condo Rento

3/12/05

4

RV

300.00

RV

0.00

25.00

3

New Orleans

RV Rentals

N/A

3/18/05

5

horse

80.00

tent

8.00

4.30

5

Big Bend State Park

Saddle Bags Ostler

N/A

3/14/05

 

Grading scale:

Code:     (76%)

                Headers, Style, Modularity (16 points)

Program header and function headers for all functions           

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

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

Correct manipulation of the structs  (15 points)

Correct implementation of recursion (15 points)

Correct calculation of combined vacations (6 points)

Correct manipulation of menus and choices (5 points)

Correct implementation of linear search (8 points)

Correct use of required control structures (4 points)

Correct function structure as required (4 points)

Proper implementation of input error checking (3 points)

Output:          (24%)

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

                Each task performs mathematically correctly (3 points each for task #1 and task #3)

                Output gives clear information to explain the values to the user (10 points)

                Output contains all the sample data and two additional data sets  (5 points)

Deductions:

                Use of continue will result in a 20 point deduction

                Use of a break outside of a switch statement will result in a 20 point deduction

                Use of global variables will result in an overall grade of 0 (zero)

                Use of goto or exit will result in an overall grade of 0 (zero)

                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.