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

 

Due Date:           Section 501 Ð Thursday, March 10th, 5:30 pm

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

 

Topic objectives:          Pointers and dynamic memory space allocation

                                                            Strings and string functions

                                                            Multi-dimensional arrays

                                                            Arrays of pointers

                                                            More control structures

                                                            Sorting

                                                            Functions, parameter passing, side effects

                                                            Modular design

 

Now that Spring Break is almost here, you are getting very specific with your vacation choices.  You are ready to create and print up possible itineraries of your vacation plans.  You are going to be using the same type of data as for the previous lab with some additional information to be input and different types of output.  You will be accepting data for 3 to 5 vacations.

 

First you will be taking in the same data as in the first lab but instead of storing it in six separate arrays you will store it in one multi-dimensional array that can hold all six types of values (note that this means that all the data must be stored as the same type of numbers.)  You comments should indicate which dimension of the array represents which piece of data <type of transportation, total cost of transportation, type of accommodation, cost of accommodation, average cost of one meal at the destination, and number of nights>.

 

In addition to this data you will also be reading in string data. The following is the input structure:

 

A)    The first data you should accept from the user should be a string giving the vacation destination (Ex: Las Vegas or Paris or Sydney, Australia.)  Each string must be saved to dynamically allocated space that is referenced from an array of pointers. 

 

B)      After the destination, you will take in the type of transportation and the cost as you did for Lab #1.  Following this, you will take in a string giving transportation details such as airline and flight number or cruise ship line and departure location.  Each of these strings will be a constant size of 120 characters and can be stored as a 2-D character array or an array of pointers to char.

 

C)     After transportation you will take in type of accommodation and cost as in Lab #1 then a string indicating the accommodation such as hotel name or bed and breakfast name.  Each of these strings will be a constant size of 80 characters and can be stored as a 2-D character array or an array of pointers to char.

 

D)    Take in average meal cost.

 

E)      Take in number of nights as in Lab #1 and get the intended departure date in dd mm yyyy format.  (number or string as you prefer) If you store this date as a number or numbers you can put it in the multi-dimensional array if desired.

 

After reading in the data for a vacation, ask the user if they wish to enter another vacation.  Make sure that you get data from the user for at least three vacations but not more than five.

 

Once you have gotten all the input data, you will use some of your previous functions to calculate costs and then create some functions to print complete vacation itineraries for each vacation.

 

With the given input data for each vacation you must do the following tasks:

 

1.       Calculate the total accommodation cost as in Lab #1 and calculate the total cost for the vacation as in Lab #1.

2.       Calculate an average per day cost for the vacation as total cost over total number of days.

3.       Print (to the screen) a vacation itinerary for the vacation which gives the destination, the type of transportation (in words, e.g. Òtraveling by RVÓ) and its cost, the transportation details from the string the user input, the type of accommodation (in words, e.g. Òstaying in the  RVÓ) and its cost, the accommodation details from the string the user input, the departure date and the return date in mm/dd/ yyyy, the total vacation cost and the average daily cost.  The itinerary should be formatted as if it were to be printed on paper and should be clear and easy to read.  It should have some sort of header indicating that your program printed it similar to what a ticket or travel agent header would be like.

 

After printing the itineraries for all of the vacations, you should also produce a vacation list summary as follows:

 

a.       Print all of the vacation destinations, total costs, and average daily costs in a list.  Print each vacation and its costs on a separate line.

b.      Sort this list by destination and print the list again in alphabetical order

c.     Sort this list again by average daily cost and print the list again from lowest daily cost to highest.

d.      Sort this list again by total cost and print the list again from lowest total cost to highest.

 

When the program is finished, print a concluding message and then end the program.

 

Implementation requirements:

The program should use the following data structures:

Multi-dimensional array for input info

Dynamic space allocation for strings

Array of pointers to strings (character arrays)

The program should NOT use the following data structures:

structs

 

The program should use the following control structures:

Function calls to perform the tasks

A while, for or do-while loop to perform calculations and output for each vacation

If, if-else, nested ifs, or a switch to check the transportation codes before asking accommodation / meal questions as in Lab #1

Sorting algorithm for numeric values

Sorting algorithm and string comparisons for string values

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 with at least one function for getting input from the user, one for creating itineraries of the vacation data, one for performing calculations, and two for sorting.  You may use more functions than this but you must use at least this many.  

 

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

                        Headers, Style, Modularity (20 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 strings including pointer declaration and dynamic memory allocation  (12 points)

Correct manipulation of the arrays of pointers  (9 points)

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

Correct implementation of sorting (6 points numeric, 6 points string)

Correct use of required control structures (4 points)

Correct function structure as required (4 points)

Proper implementation of input error checking (3 points)

Output:              (27%)

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

                        Each task performs mathematically correctly (4 points for task #2)

                        Sorted output is correctly printed(3 points)

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

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

Deductions:

                        Use of structs will result in a 10 point deduction

                        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.