Lab Assignment # 4, CSE 1320
Section 501, Spring 2005
Due
Date: Section 501 Ð Tuesday, May 10th,
5:30 pm 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: Structs using enum and unions
File input with fscanf, getline, fgets, etc.
File output
Singly-linked lists
Command line parameters
Conditional compilation
(Plus all the stuff youÕve already done)
Finally summer vacation is getting close so youÕre going to do your last modification to your vacation planning system.
First, your planner MUST use file input. The datafile(s) will use the same format specified in the last lab except in two ways. One, there will be no number of vacations on the first line (i.e. the first line will be the first data for the first vacation) and two, the departure date info will be in MM DD yyyy order which is different then previously specified.
The input for the database will be from one or more files given as command line parameters and the program will be able to run in a travel user mode or in a travel agent mode through conditional compilation.
The user may enter up to three data
files for input on the command line.
Your program must check to see how many file names were entered and must
read the data from all files that are given and store it together in one linked
list. The data in each file must
be unique.
Second, you will continue to use structs for the vacation data (with members a. Ð m. as given before) but you will be adding some additional fields to the struct as follows:
n. an enumerated type indicating if the has primarily air transportation, land transportation, or water transportation.
o. a union type which will hold one of three values:
a. a long int for max altitude in feet for air travel
b. a double for miles for land travel
c. a float for average speed in knots for water
p. a pointer to a vacation struct to use as the link
Your program will read the input data from the file into a linked list of structs that are dynamically allocated as needed. The first struct to be created will be the head of the linked list and all other structs will be added behind this struct. Each struct will be linked to the next by the vacation pointer member.
Your program should calculate average daily cost, total cost and return date for each vacation and store that data in the appropriate member of the structs. Your program should also determine the appropriate enumerated type value based on the transportation codes and should ask the user to enter the correct union value for each vacation. These should also be stored in the struct.
Your program should then print a vacation itinerary for each vacation like you did for Lab #2 and #3. You should modify your print function from Lab #2/3 to work with a linked list of structs and to print all of the data in the struct.
Now you will extend the ability of your program in the following ways. After the vacation itineraries have been printed the program must allow the user to choose one of the following options based on the mode as #DEFINEd in the program. The following five choices should be presented to the user in a menu format along with a choice to end the program. YouÕre also going to allow the user to be able to insert, delete and update records in the database in travel agent mode. The program should let the user continue to choose one of these options until the user chooses to end the program.
In travel user mode the user may choose to:
When the user chooses to end the program, print a concluding message and then end.
The program should use the following data structures:
Linked list of structs for input info
Dynamic space allocation for structs and strings for destinations
Array of pointers to strings (character arrays) or dynamic arrays for other strings
An enumerated type for the air, land or water travel
A union for the values associated with the travel
A singly linked list of structs
The struct type may be declared globally but the struct pointers and variables must be declared locally
The enum and union types may be declared globally but the variables must be declared locally
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 vacation, and allow user to choose from the menu of options
Linear search
Command line parameters
Conditional compilation preprocessor commands
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.
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.
The program should have a main function and at least four
(4) subfunctions but no more than twenty (20) subfunctions. Each function should focus on one
particular task.
Execution requirements:
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. The sample data sets that you create must meet the guidelines given in the problem definition.
At least one execution of
the program in travel user mode should demonstrate all options 1 Ð 5. At least one execution of the program
in travel agent mode should demonstrate options 6, 7, and 8 at least. These three executions must also demonstrate the use of
multiple file names on the command line to demonstrate reading in data from
multiple files in the same execution.
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 or you may run it three separate times
so that you have a total of three different data sets.
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.
nite |
||||||||||
|
||||||||||
Grading scale:
Code: (70%)
Headers, Style, Modularity (10 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 structs (15 points total)
Enum
(3 points out of the 15)
Union
(3 points out of the 15)
Pointers
to build list (9 out of 15)
Correct implementation of linked list (15 points
total)
Adding
Ð Task 6 (5 out of 15)
Deleting
Ð Task 7 (3 out of 15)
Updating
Ð Task 8 (7 out of 15)
Correct implementation of sorting the list Ð Task
4 (14 points)
Correct implementation of linear search Ð Task 1
(4 points)
Correct
manipulation of menus and choices (5 points)
Correct
use of required control and function structures (4 points)
Proper implementation of input error checking (3
points)
Output: (20%)
User clearly understands what is being requested for input (3 points)
Requested data printed correctly Ð Tasks 2 and 3 (3 points each out of 6)
Output gives clear information to explain the values to the user (6 points)
Output
contains all the sample data and two additional data sets (5 points)
Compilation: (10%)
Conditional
compilation handled correctly (4 points)
Command
line parameters implemented correctly (6 points)
Deductions:
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 qsort from textbook will result in a 30 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.