Lab Assignment # 4, CSE 1320
Section 001, Fall 2005
Due Date: Section 001 – Dec 5th , 11:00am (this is the time of the final
exam)
(see instructions on website for how to turn this in)
Topic objectives: Linked lists
Command line parameters
Separate compilation
Our spice rack program is hot stuff!! For our next upgrade, we are going to change the internal representation to make better use of space, we’re going to allow the user to enter file names when they call the program and we’re going to break the program into separate files.
We’ll start by separating the program into at least 3 files to make each file easier to work on. The three files should contain the following data and functions:
File 1: All the function prototype declarations, all the type declarations, all the preprocessor directives and the main function
File 2: All the sort functions and swap functions
File 3 (or Files 3, 4,…) : Everything else (This can be broken into more than one file if desired; for example, a file with the input functions and a file with the blend checking functions, etc. )
Make sure to properly handle the declarations for external items and test this as you go.
Next we’re going to modify the files that the user reads input from. Previously the files had to have specific names to be used. Now though we are going to use command line parameters to pass in the files with the spices and the blends. The formats for the files will be the same as in the previous lab but now the files can have any names. (It is suggested to use .txt or .dat as the file extensions for these files and to have meaningful file names – NOT file1.txt but lab4spicefile1.txt for example.)
Our biggest change is going to be changing from using an array of spice structures to using a doubly linked list of spice structures. This means first that the spice structs will need to include pointers to the same struct types inside them in order to create links and second that we will be allocating space for the spice structs as they are needed - not declaring a fixed amount of space up front. The spice data list should also be created as a sorted listby the amount of each spice. The blend data structures will still be stored in a fixed array of size six since there will be exactly six blends again.
Once we change the structure from an array to a linked list, we must then go back and modify our functions to work on the linked list. The most challenging functions to modify are the sorting and swapping functions. Since these are the most difficult, we will be modifying only the selection sort and the bubble sort to use the linked list. You do NOT have to modify the merge sort to work on the linked list. If you do modify the merge sort for linked lists, you will receive up to 15 points extra credit. Remember to change the menu of options to reflect which sorts will work in the new version of the program.
You can use the sample data files from Lab #3 as one set of input data. You must run the program with three different files of spice input data using the different spice file names on the command line each time. You may use the same blend file each time or use alternate blend data files.
Implementation requirements:
The program should use the following data structures:
Linked list of structs for spices as defined above
Array of 6 structs for blends
The program should use the following control structures:
Function calls to perform tasks
Loops as needed
Selection statements as needed
Separate compilation of three or more files
Command line parameters for file name input
The program should NOT use the following control structures:
breaks outside of switch
structures
continues
gotos
exits
any topic not covered in class before the lab DUE date unless approved by the instructor
The program should be implemented as a set of functions as
in the previous labs You should use at
least 8 functions. 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 value from the keyboard
Perform appropriate calculations and 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, 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 for the spice rack contents and one data set for the spice
blends. The first data set (dataset 1)
will be given as a file on the website. You must also create two additional
data files and run your program with them as well. A file containing half the required blend data will also be
posted on the website. You must add
seasoning blends up to a total of 6 blends.
You may run the program 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 datasets 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, it is your responsibility to ask the TA or OIT how to use this function.
Grading scale:
Code: (73%)
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!) Follows the function structure
requirements given
Correct use of multiple files for the program (9
points)
Correct modifications of spice structs with
pointers for linking (6 points total)
Correct use of file input from command line file names (8 points)
Correct creation of sorted linked list (15 points)
Correct modification of selection and bubble
sorting for linked lists (10 points)
Correct modification of blend checking functions
to use linked lists (10 points)
Correct use of required control structures (4 points)
Proper implementation of input error checking for
quantities and costs (3 points)
Output: (27%)
User clearly understands program options throughout program execution (5 points)
Including message about use of command line parameters if needed
Sorted output is correctly printed (3 points)
Modification
of existing functionality with new data structures is done correctly (8 pts)
Output gives clear information to explain the values to the user (5 points)
Output contains all the sample
data and two additional data sets (6
points)
Extra credit (15%)
Correct modification of merge sorting for linked lists (15 points)
Deductions:
Use of global variables will
result in an overall grade of 0 (zero)
NOTE: Types are allowed at be defined globally
Use of the goto or exit commands will
result in an overall grade of 0 (zero)
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
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.