Lab Assignment # 2 and #3, CSE 1320 Sections 501, Summer 2005

 

Due Date:             Section 501 –      Lab #2 part due: July 25th, 6:00 pm

                                                                Lab #3 part due: August 1st, 6:00 pm

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

 

Topic objectives:       Pointers and dynamic memory space allocation

                                        Strings and string functions

                                        Structs, enum and unions

                                        Arrays of structs

                                        More control structures

                                        Sorting

                                        Recursion

                                        Functions, parameter passing, side effects

                                        Modular design

 

The musician liked your first program.  Now you need to upgrade your system for more functionality.  Your first upgrade will be to create structs that can hold all the data for one venue in a single place.  With this struct type, you can then create an array of structs and read the input venue data into the array of structs. 

 

The struct must hold the following pieces of data:  (Additional details are given below)

Lab #2 and #3

a.       A pointer to the name of the venue

b.       Transportation type using the same codes as Lab # 1

c.        Transportation cost

d.       Transportation details string

e.        Accommodation type using the same codes as Lab # 1

f.         Accommodation cost

g.       Accommodation details string

h.       Average cost of one meal

i.         Number of people who will stay at the destination for 2 days and 2 nights

j.         Departure date in mm dd yyyy format

k.       Total cost per venue (calculated by your program)

l.         Average cost per person in the entourage (calculated by your program)

m.     Total revenue per venue (calculated by your program)

Lab #3 only:

n.       Total transportation cost (calculated by your program) [Lab #3 ONLY]

o.       Total accomodation cost (calculated by your program) [Lab #3 ONLY]

p.       Total meal cost (calculated by your program) [Lab #3 ONLY]

q.       Field indicating whether transportation, accommodation or meals are most costly. (determined by your program) [Lab #3 ONLY]

 

You program must declare an array of 10 or more of these structs.

 

In addition to the data you read for Lab # 1 you will also be reading in string data. The following gives the details for the input items listed above:

 

A)   The first data you should accept from the user should be a string giving the venue (Ex: ”The Sands in Las Vegas” or “The Eiffel Tower in Paris” or “The Concert Hall in Sydney, Australia”.)  Each string must be saved to dynamically allocated space that is referenced by a pointer. 

 

B)    After the venue, 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 character array or a pointer 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 character array or a pointer to char.

 

D)    Take in average meal cost.

 

E)    Take in number of people in the entourage who will be staying two days and two nights) as in Lab #1 and get the intended departure date in mm dd yyyy format.  (number or string as you prefer)

 

 

After reading in the data for a venue, ask the user if they wish to enter another venue.  Make sure that you get data from the user for at least three venues.  [Remember when testing you might make the loop shorter and enter only one venue instead of the required minimum to make it quicker to test.  Then when it works, change it back to 3 venues minimum.]

 

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 comparison information for each venue.

 

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

 

Lab #2 and # 3 tasks:

1.     Calculate the total cost for the venue as in Lab #1 and store in the struct.

  1. Calculate an average per person cost for the venue as total cost over total number of entourage members.  Store this in the struct.
  2. Calculate and store total revenue for the venue using the formula in the first paragraph.
  3. Print (to the screen) a venue comparison 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 total number of people in the entourage, the total venue cost, the average per peson cost, and the total venue revenue.  The comparison 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 what your program is for and what the information on the page is for.

Lab #3 only tasks:

  1. Calculate and store total transportation cost, total accommodation cost, and total meal cost for each venue in the struct.
  2. Create an enumerated type containing three values – transportation, accommodation, and meals.  (You may abbreviate these if you want).  Determine which of these three total costs is largest for the venue (using the values from task 6) and store the corresponding enumerated type value in the struct.  (Ex:  If meals are most expensive, then store the enumerated value meals in the struct.)
  3. Modify task 4 above to print the comparisons including the data from task 5 and 6 in the output.

 

After printing the comparison sheets for all of the venues, you should also allow the user to perform the following tasks::

 

Lab #2 and #3 tasks:

  1. Allow the user to stop running the program.  Print a concluding message and then end the program.
  2. Print a summary of all of the venue destinations, total revenues, and average per person costs in a list.  Print each venue and its costs on a separate line and number each line.  This is called the summary page.
  3. Allow the user to enter a dollar amount and then use linear search to go through the venue struct array and print out for the user all the venues that produce revenue over that amount.  Make sure to label the output
  4. Print a list of venue destinations for the user (the summary) and let them find out the average per person cost from combining two venues, i.e. if the user chooses venues 1 and 3, then give them an average per person cost using total cost of venue 1 cost plus venue 3 cost minus the cheaper of half of each of the two transportation costs.  (Make sure to check that the same number of people were in both entourages at the venues and accommodate for different numbers if they exist.)  Label your output.

Combined per person cost of venues a and b =

[Total cost venue a +

Total cost venue b -

Minimum ((Transportation cost of a / 2) or (Transportation cost of b / 2))]

    Divided by number of entourage members

Lab #3  only tasks:

  1. Sort the  list by venue and print the entire comparison list again (with all pieces of information – not the summary page)  in alphabetical order.  Use a recursive merge sort to implement this.
  2. Sort the list again by total revenue and print the entire comparison list again from lowest total revenue to highest.  Use bubble sort to implement this.
  3. Print an alphabetical list of only those venue destinations that have total transportation as their largest cost.
  4. Print an alphabetical list of only those venue destinations that have total accommodation as their largest cost.
  5. Print an alphabetical list of only those venue destinations that have total meals as their largest cost.

 

 

 

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 venue, and allow user to choose from the menu of options

Recursive algorithm for calculating option 3

Linear search for option c  (Lab #2 and #3)

Merge sort for option e (Lab #3)

Bubble sort for option f (Lab #3)

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 printing the venue data, one for performing calculations, one for searching and two for sorting (Lab #3) 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 at least 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 three different times 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:   

No.

Venue

Trans type

Trans cost

Accom. type

Acc cost

Avg meal $

Num of people

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

rent house

400.00

85.00

14

5

 

tour bus

99.99

tour bus

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

 

tour bus

120.00

hotel

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

 

Lab #2 Grading scale:

Code:     (60%)

                Headers, Style, Modularity (14 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!)  Appropriate minimum number of functions.

Correct manipulation of the strings including pointer declaration and dynamic memory allocation  (12 points)

Correct manipulation of the structs  (15 points)

Correct calculation of combined venues (6 points)

Correct manipulation of menus and choices (5 points)

Correct implementation of linear search (8 points)

Output:          (40%)

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

                Each task performs mathematically correctly (3 points per task 1, 2, 3, and d.) {12 total}

                Searching and summary tasks are performed  correctly (10 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)

 

 

Lab # 3 Grading scale:

Code:     (60%)

                Headers, Style, Modularity (8 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!)  Appropriate minimum number of functions.

Correct manipulation of the enumerated type  (4 points)

Correct addition of members to the structs  (4 points)

Correct determination of largest in task 6 (4 points)

Correct manipulation of menus and choices (5 points)

Correct implementation of bubble sorting (10 points)

Correct implementation of merge sort using recursion (15 points)

Correct use of required control structures (6 points)

Proper implementation of input error checking (4 points)

Output:          (40%)

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

                Each task performs mathematically correctly (5 points for task 5.)

                Comparison output is modified correctly (4 points)

                Sorted output is correctly printed(4 points)

                Sublists output correctly (3 points each per task g, h, i) {9 total}

                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 for both Labs #2 and #3:

                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)

                A program that compiles with warnings or errors 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.