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.
Lab #3 only tasks:
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:
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:
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.
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.