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

 

Due Date:                  Section 501 – Feb. 15tht, 5:30 pm

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

 

Topic objectives:                                Arithmetic

                                Control structures

                                Functions

                                1 - dimensional arrays

                                Programming style

 

School’s just getting started so you are already planning your vacation at Spring Break.  In order to make your travel plans you’ve decided to write a program that will capture data about different vacations and will assess different aspects of each vacation to help you make the best choice based on your criteria.  These aspects will include cost, location, length, type of accommodation, and type of transportation. 

 

Since your finished vacation planner will probably be a big fancy system, you’ve decided to start by creating a system to calculate and compare the cost of a given vacation.  You will enter the number of vacations to compare and for each vacation, the type of transportation and its cost, the type of accommodation and its cost, the average cost of one meal at the destination, and the number of nights you will stay at the destination.  You will then calculate a total cost for each vacation.  The following are the tasks you must do:

 

First you must create 6 arrays.  The arrays must have at least ten elements but can have more.  Each array will store a single type of data for a vacation.  Each element of the array corresponds to a particular vacation in numerical order.  E.g. The array element [1] would correspond to Vacation #1. The six arrays are:

  1. Type of transportation where the array element value will be: 0 = none, 1 = automobile, 2 = recreational vehicle (RV), 3 = bus, 4 = plane, 5 = boat, 6 = cruise ship, 7 = train, 8 = other
  2. Total cost of transportation to and from vacation destination stored as dollars and cents.  (xxx.xx)
  3. Type of accommodation where 0 = none, 1 = tent, 2 = recreational vehicle (RV), 3 = bed & breakfast (B&B), 4 = hotel, 5 = rental home, 6 = cruise ship, 7 = other.  However, if transportation code was 6 above then program should automatically assign 6 as the accommodation code and should assign a cost of 0 for accommodation cost and average meal cost without asking the user.  If the transportation code was 2, then the accommodation code should be set automatically to 2 and the accommodation cost to 0.00.
  4. Cost of accommodation for a single night stored as dollars and cents
  5. Average cost of one meal at the destination as dollars and cents
  6. Number of nights you will stay at the destination

 

Now you must print some sort of introduction for the user and then  ask the user how many vacations they will be comparing.  The minimum number is five and the maximum is the size of your arrays declared above (10 or larger if you made your arrays larger)

 

Next you must request data from the user to fill the arrays.  [When testing you might make the loop shorter and enter only two vacations instead of the required minimum of 5 to make it quicker to test.  Then when it works, change it back to 5 vacations minimum.]  You must ask the user for information for each array.  For example, your program could ask:

 

Ask similar questions for all of the data needed for each of the vacations to be compared: type of transportation and its cost, the type of accommodation and its cost per night, the average cost of one meal at the destination, and the number of nights. 

 

After input is done, print out the data for each vacation to the screen.

 

After this you will perform the following calculations and output the results:

  1. For each vacation, calculate and print the total accommodation cost by multiplying the cost per one night times the number of nights and print this info with a label
  2. For each vacation, calculate total cost by adding transportation cost plus total accommodation cost plus total average meals.  Total average meals is average meal cost times ((three times number of nights) + 2).  Print these results.
  3. Find the maximum cost of any the vacations on the list and print this value indicating which vacation number it is and find the minimum cost and print it.   Also print the minimum number of nights of any of the vacations and the maximum number of nights of any of the vacations.
  4. Find the average cost of all the vacations on the list and print this total.

 

After this is done, your program must ask the user if they wish to run the vacation comparison again and if so, go back to the beginning and request the user to enter new values for all data.  If the user is finished, print a concluding message and then end the program.

 

Implementation requirements:

The program should use the following data structures:

Integer array for transportation codes

Floating point array for transportation costs

Integer array for accommodation codes

Floating point array for single night accommodation costs

Floating point array for average meal costs

Integer array for number of nights to stay

 

The program should use the following control structures:

Function calls to perform the tasks

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

If, if-else, or nested ifs to check the transportation codes before asking accommodation / meal questions

 

The program should be implemented as a set of functions with at least one function for getting input from the user, one for printing the vacation data, and one for performing calculations.  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

Print the appropriate outputs

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

 

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:   

Vacation

Transportation type

Trans cost

Accommodation type

Acc cost

Avg meal cost

Number of nights

1

car

40.00

hotel

120.00

8.00

10

2

cruise ship

1400.00

cruise ship

0.00

0.00

7

3

plane

448.12

B&B

72.00

12.00

8

4

none

0.00

rental house

400.00

85.00

14

5

bus

99.99

tent

10.00

3.50

9

6

RV

100.00

RV

0.00

25.00

3

7

train

250.00

none

0.00

13.00

15

8

horseback

80.00

tent

8.00

12.00

5

9

plane

162.18

hotel

423.88

56.00

2

10

car

240.00

B&B

52.00

17.50

8

 

Grading scale:

Code:     (66%)

Program header and function headers for all functions        (8 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!)  (10 points)

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

Correct manipulation of the 1-dimensional arrays  (10 points)

Correct use of required control structures (10 points)

Correct function structure as required (10 points)

Proper implementation of input error checking (8 points)

Output:          (34%)

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

                Each task performs mathematically correctly (4 points per task 1, 2, 4.)

                Maximum and minimum values are found correctly (4 points)

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

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

Deductions:

                Use of global variables 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.