Lab Assignment # 4, CSE 1320 Sections 001 and 501, Fall 2004

 

Due Date:                  Section 501 – Tues, Dec 7th, 5:30 pm Final Exam time

Section 001 –Mon, Dec 6th, 11:00 am. Final 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:                                Doubly-linked lists

                                Command line parameters

                                Conditional compilation

                                (Plus all the stuff you’ve already done)

 

One last task for your bookstore, Plus or Minus Perfect Books (or ‘±Perfect’ for short).  The database that was set up in the last program was a good start but you’ve decided to make your database a little more robust and more flexible.  You’re going to change the structural representation from an array of structures to a sorted doubly-linked list of structures to accommodate any amount of books in your input files.  You’re also going to allow the user to be able to insert, delete and update records in the database.  The database will still need to be able to be sorted by title and ISBN but will also be able to be sorted by other fields as well.  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 data entry mode or in an administrator mode through conditional compilation.

 

For this task you will use the struct that you designed for the previous lab.  You will need to add two pointers to the struct that can point to other structs of the same type.   You will be reading in data for each struct from an input file but you will not know how many book records are in the file so your program must read until it reaches the end of the file.  This also means that each struct must be allocated individually as it is needed. 

 

The data that is read in for a given book must be stored in the doubly-linked list in order sorted by ISBN number from smallest to largest.  So you must create this sorted list as you read in the book data.  The data in the input file will be exactly the same format as used for the previous lab except that there will be no integer on the first line of the file – this line will be the first title.

 

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 sorted array.  The data in each file must be unique.

 

After all the data in all the files have been read in the program should print out all the book inventory information in some moderately easy-to-read format to verify that the data has been sorted in the linked list correctly.

 

After the book inventory has been printed the program must allow the user to choose one of the following options based on the mode as #DEFINEd in the program:

        In user mode the user may choose to:

1)       Print a list of book titles only in the current order

2)       Print a list of authors (first_name middle_initial last_name) only in the current order

3)       Sort the list by ISBN number and print the titles and ISBN numbers after the list is sorted.

4)       Sort the list by book title and print the list of titles and author’s last names after the list is sorted. (Don’t worry about the rules for “The” and “A”)

5)       Sort the list by wholesale or retail price and print titles and prices in descending order of price.

6)       Sort the list by original publication date and print titles and dates oldest to newest.

7)       Sort the list by author last name (and first name if needed) and print titles and author’s full name in complete alphabetical order.

8)       End the program

        In administrator mode the user may choose any of the above options as well as the following options:

9)       Add a new book to the database and insert it into the list in ISBN order and print the list after the addition.

10)   Delete a book from the database and print the list after the deletion.

11)   Change the values in any member field of an existing book in the database and print that book after the change is complete.

The user must be allowed to continue choosing from the valid options until they select the option to end the program.

 

For options 3 and 6, your program should use a recursive quicksort algorithm to sort with.  Use and modify the function you created for you last lab for this sort.

 

For options 4 and 7, your program should use a bubblesort algorithm to sort with based on comparisons of the strings using the string functions in C.  Use and modify the function you created for you last lab for this sort.

 

For option 5, you may choose any sorting algorithm.

 

When the user  is done, print a concluding message and then end the program.

 

Implementation requirements:

The program should use the following data structures:

At least one struct type with pointer members and dynamically allocated structs as described above

An enumerated type for the book format

A union for the values associated with the book format

A doubly 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 variable must be declared locally

 

The program should use the following control structures:

Recursion (in the quicksort)

Command line parameters

Conditional compilation preprocessor commands

Other control structures already discussed as needed

The program should NOT use the following control structures:

breaks outside of switch structures

continues

gotos

exits

 

The program should also use the following:

File input for the book data

 

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.

 

This program must be run with at least three different input files.  The first data set (data set 1) should use the values given in the file that is linked to this lab assignment (which is the data from Lab3 without the first integer).  You must also create at least two additional data files (with at least 5 unique books each) and run your program with them as well.

 

You must execute the program three different times.   The sample data sets that you create must meet the guidelines given in the problem definition.  Each execution of the program in user mode should demonstrate options 1 – 8.  Each execution of the program in administrator mode should demonstrate options 9, 10, and 11 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.

 

General implementation requirements for all assignments:

The program should perform the roughly 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 values

Print the appropriate outputs

Let the user enter additional info or choices 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.

 

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:     (84%)

                Headers, Style, Modularity (12 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 modification of struct type to contain all required data  (4 points)

Correct declaration of pointers to struct to use for allocation and linked list (7 points)

Correct allocation of memory for array of structs (6 points)

Correct modification of swap for linked list (2 points)

Correct modification of quicksort algorithm for linked list (2 points)

Correct modification of bubblesort algorithm for linked list (2 points)

Correct implementation of sorts on title (2 points), name (3 pts), ISBN (2 ), year (3), prices (3)

Correct implementation of adding element to list ( 6 points)

Correct implementation of deleting element from list ( 4 points)

Correct implementation of updating element in list ( 5 points)

Proper implementation of user mode (4 points)

Proper implementation of administrator mode (4 points)

Correct command line parameter manipulation (5 points)

Correct implementation of conditional compilation (8 points)

Output:          (16%)

                Output gives clear information to explain the values to the user (6 points)

                Output contains all the sample data and at least two additional data sets  (10 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)

                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.