Lab Assignment # 4, CSE 1320-501,Spring 2004

 

Topic objectives:       Linked lists

                                        Command line arguments

                                        Sorting

                                        Code reuse

                                        Multiple files

                                        Conditional compilation

                                        File I/O

Due Date:                     May 11h, 2004 at exam time.   Early submission is worth 1 point extra per day up to 10 points.  ***NO LATE LABS WILL BE ACCEPTED FOR THIS ASSIGNMENT***  This is to allow enough time for semester grades to be finalized and turned in.

 

Wow!  The semester is nearly over and we need to do some final organizing of our artwork data.  Even since the last database your collection has changed so now you will be recording the artwork again but this time in a linked list instead of an array.  You will also sort the data in the linked list in two different ways depending on what the user requests.  Lastly, you will be collecting some total information about the collection.  The sorted collection information and the totals will be printed to the screen for the user and recorded in an output file.  The goal is to do this by using as much of your previous lab code as possible.  For this lab, new code and the main routine should be in one (or more) file(s) and the reused code – even slightly modified – should be in a separate file.   There will also be the ability to compile this program as the full version or to compile a limited version that has the same input capabilities but more limited options for the user.  This will be done with conditional compilation

 

For this assignment you will use the same struct as in the previous assignment (struct Artwork) with one additional field in it.  You will modify the struct type to include a pointer to a struct Artwork.  Call this pointer Nextwork.  (This also means that you must still calculate expected appreciation and insured value as you did in Lab 3)

 

You will again read data from a file but this time you will pass the actual file name into the program as a command line argument.  This means that if your data is in the file myvals.txt then you would execute your program by typing:

Ø       a.out myvals.txt

You may name your data file in any way that you prefer.  This file will then be opened using a file variable in the program.

 

Your program will also produce output that is printed to a file and to the screen.  The actual output file must be named “outlab3.txt”.  You will open this file for writing.  The output described below should be written to the file and to the screen unless otherwise noted.

 

Your program should do the following:

1.       While there is artwork in the file that was passed in from the command line:

a.                   Read in all the information about one piece of art from the input file into a newly allocated struct.

b.                   Calculate the Insured_value and Expected_appreciation for that piece of art and store those values in the same struct

c.                    Link the new struct into the singly-linked list of artwork (using the Nextwork pointers) in alphabetical order by artist’s last name.

2.       Continue reading all of the artwork until the program reads XXX for a title.

3.       When all of the pieces of art are stored in the linked list, allow the user to choose one of the following options.  NOTE:  Be sure to include appropriate messages to indicate what the data means that is being output.  After the user’s request is complete, the user should be able to continue choosing options until they choose option k below:

a.       Print all the information about a piece of art into the output file and to the screen.  This should be done using the same switch statement structure for output as in Lab 3 plus the information about years and value.  Add output statements that print the data to the output file.

b.       Print just the title and artist of all the artwork to the output file and to the screen.

c.        Sort the list by the year the art was created and print this sorted list to the screen and to the file.  Print all information for each piece to the file but only print title, artist and year of creation to the output screen.  (This information can be printed with just a single piece of data on each line similar to the data in the input file.)

d.       Sort the list by the titles and print this sorted list to the screen and to the file printing only title, artist and current value to both outputs.  This data should be printed on a single line as a sentence or as a set of labeled values; i.e. either like the switch statement output or “Title -  Teddy:  Artist – The Bear:  Value – 10.00” or something of the sort.

e.        Sort (or resort) the list by the artist last names and print this sorted list to the screen and to the file printing only title, artist and medium to both outputs.  For the medium print the full word or phrase not just the single character; i.e. “Photograph”  instead of ‘O’.   Again use a sentence or a set of labeled values.

f.         Calculate and print the total initial cost of all the art in the collection to the file and the screen. 

g.       Calculate and print the total current value of all the art in the collection to the file and the screen. 

h.       Calculate and print the total insured value of all the art in the collection to the file and the screen. 

i.         Calculate and print the total expected appreciation of all the art in the collection to the file and the screen.

j.         Print the number of pieces of art in the collection

k.       Exit the program.  Be sure to print a final message to indicate that the program is ending.

4.       The program should also support an alternate structure through the use of conditional compilation.  If the conditional flag is set to LIMITED then your program should compile such that the user only has the options a, d, j, k and one other option l (lower case L) that calculates and prints all the information from options f through i above.

 

 

Implementation requirements:

The program must use the following data structures and types:

A struct type called Artwork containing two character pointers (for title and artist), a char, four long doubles and five ints for the 12 pieces of data about each artwork plus a pointer to a struct Artwork.

One or more pointers to Artwork structs which will be used to manage and traverse the linked list.

 

The program must use the following control structures:

Conditional compilation instructions and a #DEFINE flag named LIMITED

A function to read the input data from the file.  If possible, reuse the function from Lab #3.

A recursive function to calculate the Expected_appreciation and the Insured_value.  Reuse the functions from Lab #3.

Reuse the switch statement from your previous lab for the output and the additional sentence of output as directed above.

A loop to let the user choose options

 

The program should perform the following actions in the given order:

Define the struct type

Declare and initialize the variables

Open the input file for reading using the argument from the command line

Open the output file for writing

Print a short introduction to the system for the user

Go through the input file and for each piece of art:

Get the needed input values from the file

Calculate the Expected_appreciation and the Insured_value as each new item is read

Sort the item into the linked list by the artist’s last name.  If this is the first artwork, make it the first element in the linked list.   (For additional information on linked lists see the Powerpoint presentation that Dr. T will be posting on the 1320 web page.)

After all the data is input, give the user the choice of options described above until the user chooses to end the program.

 

The program must  consist of at least two program files.  One file will have the main routine and any new functions that are written.  The second file will have all reused functions even if these functions are somewhat modified to meet the new requirements.  The files must be connected with appropriate extern declarations.

 

All files should have appropriate conditional compilation instructions to allow the two versions of the program – the full version as defined and the LIMITED version as noted above. 

 

As in all labs, 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 using the sample input given below (at the very end) AND must be run using your own sample data as well (at least 5 additional items added to the input file).  The sample data set that you create must meet the guidelines given in the problem definition.

 

The script file must contain two different compilations of the program – one full version and one LIMITED version.  The same inputs should be run on both versions.  After the completion of the program run, the output file should be printed to the screen so that it is captured in the script file.  The output file should be submitted with the program when it is turned in.

 

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 read the instructions on  my website and to  ask the TA or OIT how to use this function.   REMINDER:  Do NOT name the script file the same as the source code file!  Use a .txt or .dat extension on the script file.

 

 

Topic objectives:       Linked lists

                                        Command line arguments

                                        Sorting

                                        Code reuse

                                        Multiple files

                                        Conditional compilation

                                        File I/O

 

 

Grading scale:

Code:      (72%)

Correct manipulation of linked list (20 points)

Correct sorting of linked list (18 points)

Correct use of command line argument for file input and correct file output (6 points)

Correct use of conditional compilation (6 points)

Correct use of multiple files (5 points)

Correct reuse and modification of Lab #3 code (7 points)

                Good Programming Practices (10 points)

Reasonable error checking of numeric values and defined values such as Medium

Assumptions stated for what inputs are expected and are accepted and checked  

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!)

Output:          (28%)

                Output follows the form given above – options 3a through 3k  (15 points)

                Correct numeric calculations for 1b and 3f – 3i  (5 points)

                Output (can be more than one session of running the program) contains all the sample data, both versions of the compilation, and at least 5 more additional input values  (8 points)

 

 

Sample input values to test in your own input file.  Copy the data into a TEXT (.txt) file and use it as input.

 

Judith and Holofernes

Klimt, Gustav

A

650000.00

130

50

3

1928

2004

650000.00

Esker Trefoil Torus

Ferguson, Helaman

S

18000.00

250

400

300

1994

1999

15000.00

La Betes du la Mer

Matisse, Henri

O

35000.00

225

80

4

1950

2000

42000.00

Mickey Mouse

Disney, Walt

E

1000000.00

3

2

-5

1935

1995

8000000000.00

In The Courtyard

Schou, Sandra

A

450.00

35

65

3

 1992

2004

450.00

A Day at the Office

Bradford, C. J.

I

50.00

80

60

1

1996

2002

5.00

Mother and Child

Williams, Mildred

A

200.00

85

40

2

1963

1999

0.00

Venus of Willendorf

Anonymous

C

4000000.00

9

5

4

2

1923

0.00

Emerald Vase

de Tirtoff, Romain (Erte)

I

22000.00

22

18

2

1935

1998

16000.00

Composition 17 (The Oarsmen)

Kandinsky, Vassily

A

46000.00

43

43

2

1918

1975

25000.00

XXX