Lab Assignment # 4, CSE 1320
Sections 501, Summer 2005
Due Date: Section 501 – August
10th at exam time
Extra credit – 2 points per day extra credit for early turn in up to one week (15 points max)
(see instructions on website for how to turn this in)
Topic objectives: Conditional compilation
File input
Command line parameters
Singly
linked lists
(Plus all the stuff you’ve already done)
For this last system upgrade you will be changing where the input comes from and how the data is stored in memory. You will still be using the same structs as in Lab #2. with some additional members as described below. However, the input data will be in a file whose name is passed in from the command line and rather than storing the input data in an array of structs, you will be creating a linked list of structs.
The struct must hold the following pieces of data: (Additional details are given below)
Lab
#4
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)
n.
A
pointer to another struct of this same type used to link the list
The input file will have one piece of data on each line for struct members a. – i. and will have three (3) numbers on one line in mm dd yyyy format for item j. The data for line a. will be the string giving the name of the destination. No data will be in the file for items k. – n. The destination for the first venue will be the first line of the file and the line immediately following the date for the first venue (item j.) will be the destination (item a.) for the second venue. There will be no blank lines between the venues in the file.
Your program should be designed to be conditionally compiled. Declare a flag called LIST to use in order to compile your program and store the structures as a linked list. If the flag is NOT declared, your program should compile and read data into an array of structs as you have been doing (note this means that you still have to read from the file either way so you may want to read into a temporary structure and then assign that struct into your array or list). NOTE: if you do not wish to implement the conditional compilation ( a 10 point deduction) then make your Lab #4 work ONLY with linked lists as defined in all the tasks.
Your program will read the input data from the file into either a linked list of structs that are dynamically allocated as needed or an array based on the flag LIST. For the linked list, the first struct to be created will be the head of the linked list initially. The other structs will be added to the list in order sorted by destination name (item a.). Each struct will be linked to the next by the venue struct pointer member. For the array, your program would just store the data in the order it is read in as you have been doing.
You will need to modify your program so that the tasks for Lab#2 can now be performed on the linked list of data. Since you can compile your program with linked lists or arrays, you should have one version of the task for an array and another version for the linked list and compile those in based on the flag. You do NOT have the revise the Lab#3 tasks like the sorts - just leave them for use with the arrays not with the linked list.
Lab #4 tasks for linked lists:
1. Calculate the total cost for the venue as in Lab #1 and store in
the struct.
After printing the comparison
sheets for all of the venues, you should also allow the user to perform the
following tasks::
Lab #4 tasks for linked lists:
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
After this is done, your program must allow the user to perform other tasks with the linked list or array until the user wishes to stop the program. If the user is finished, print a concluding message and then end the program.
Implementation
requirements:
The program should use the following data structures:
Singly linked sorted list of venue structures
The program should use the following control structures:
Command line parameters
Function calls to perform the tasks
Conditional compilation
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 file and sorting it into the linked list, one for
printing the venue data from the list, one for searching 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 (if any)
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 put into a file. You must also create two additional data sets in two different files 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 #4 Grading scale:
Code: (70%)
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
use of conditional compilation (10
points)
Correct
use of command line parameters (8 points)
Correct
manipulation of files for input (10 points)
Correct
manipulation of the structs to create a linked list (12 points)
Correct
manipulation of the structs to create a sorted linked list (10 points)
Correct
manipulation of menus and choices (4 points)
Correct
implementation of linear search for linked list (8 points)
Output: (30%)
User clearly understands what is being requested for input or menu selection (5 points)
Each task performs mathematically correctly (7 points)
Searching and summary tasks are performed correctly on linked lists (5 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 for Lab #4:
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)
NOTE:
The
use of global declarations of structs and data types is allowed.
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.