Lab Assignment # 3, CSE
1320-501,Spring 2004
Topic objectives: Recursion
Arrays
of structs
Due Date: April 8th, 2004
Your art collection has grown tremendously. You now have well over 30 pieces in the collection. In fact while you know it is less than 75, you’re not even sure how many pieces of art you have. You have been putting information about them into a file each time you buy a new piece but your file is pretty large now. You’ve decided to create your own mini art database to keep track of everything and to calculate some info about each piece.
In addition to the data read from the file, the struct for an artwork will also need to contain four more pieces of data:
an int to hold the year (4 digits) that the artwork was Created,
an int to hold the year (ex. 1962) that the artwork was Acquired,
a long double to hold the Initial_cost of the artwork (i.e. how much you paid for it),
a long double to hold the Insured_value for the artwork, and
a long double to hold the value for the artwork’s 10-year Expected_appreciation.
The first three of these values will also be in the file with the information you have used previously. These values for Insured_value and Expected_appreciation will be calculated as follows:
A) The 10-year Expected_appreciation is calculated recursively based on the medium of the artwork and the artwork’s current value.
1. For the mediums of photo(O), print(I), ceramic(C), textile(T), or something else(E),
a. One year’s appreciation is Artwork_value * 1.02
b. To find the expected appreciation for k years, calculate the appreciation of k-1 years * 1.02
2. For the mediums of painting(A), wood(W), stone(S)
a. One year’s appreciation is Artwork_value * 1.05
b. To find the expected appreciation for k years, calculate the appreciation of k-1 years * (1.05 + (0.01* k))
B) The Insured_value is calculated recursively based on the medium of the artwork and the artwork’s initial cost.
1. For the mediums of photo(O), print(I), ceramic(C), textile(T), or something else(E),
The Insured_value is calculated as 7 years worth of appreciation from the Initial_cost of the artwork. (i.e. the same calculation as above but using Initial_cost instead of Artwork_value)
2. For the mediums of painting(A), wood(W), stone(S)
The Insured_value is calculated as 10 years worth of appreciation from the Initial_cost of the artwork. (i.e. the same calculation as above but using Initial_cost instead of Artwork_value)
In this program, you will need to create a struct type that can hold all the data for a single artwork as described above. You will create an array of these structs and read each new item from the file into the next struct element in the array.
The data for each work of art will be read from a file. The data types for each item are as previously described either in this lab or an earlier lab. Each piece of data will be on a separate line as shown below:
Created
Acquired
Initial_cost
Since you are not quite sure how many items there are, the last item will have XXX on the line following its initial cost.
Your program should do the following:
1. While there is artwork in the file:
a. Read in all the information about one piece of art from the input file into a struct in the array.
b. Calculate the for Insured_value and Expected_appreciation for that piece of art and store those values in the same struct
2. Continue reading all of the artwork until the program reads XXX for a title.
3. When all the pieces of art are stored in the array do the following for each artwork in the array:
I. Use a switch statement based on the medium to print out its information as follows:
a. For A, print “The painting Title_of_artwork by Artist_name is Height by Width centimeters and is valued at Artwork_value”
b. For O, print “The photograph Title_of_artwork by Artist_name is Height by Width centimeters and is valued at Artwork_value”
c. For I, print “The print Title_of_artwork by Artist_name is Height by Width centimeters and is valued at Artwork_value”
d. For W, print “The wood work Title_of_artwork by Artist_name is Height by Width by Depth centimeters and is valued at Artwork_value”
e. For S, print “The stone work Title_of_artwork by Artist_name is Height by Width by Depth centimeters and is valued at Artwork_value”
f. For C, print “The ceramic Title_of_artwork by Artist_name is valued at Artwork_value and is Height by Width by Depth centimeters”
g. For T, print “The textile work Title_of_artwork by Artist_name is valued at Artwork_value and is Height by Width by Depth centimeters”
h. For E, print “The artwork Title_of_artwork is valued at Artwork_value, is Height by Width by Depth centimeters and was created by Artist_name”
II. Following the information just printed, on the next line print “The artwork was created in Created and purchased in Acquired for a cost of Initial_cost”
III. Next compare the Insured_value and Expected_appreciation for that artwork and do the following:
a. If the Insured_value is less than 80% of the Expected_appreciation print on the next line “Consider increasing insurance value of Insured_value to expected appreciation of Expected_appreciation.” Keep track of the number of underinsured pieces of art.
b. If the Insured_value is greater than 150% of the Expected_appreciation print on the next line “Consider decreasing insurance value of Insured_value to expected appreciation of Expected_appreciation plus 20%.” Keep track of the number of overinsured pieces of art.
c. Otherwise, print on the next line “Insurance value is Insured_value with expected appreciation of Expected_appreciation.”
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.
An array of Artwork structs large enough to hold all the possible items of artwork.
The program must use the following control structures:
A function to read the input data from the file
A recursive function to calculate the Expected_appreciation and the Insured_value
If possible, reuse the switch statement from your previous lab for the first part of the output. (This assumes that your switch statement worked properly before. If not, correct it and then use it.)
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
Print a short introduction to the system for the user
Get the needed input values from the file calculating the Expected_appreciation and the Insured_value as each new item is read
Print the appropriate outputs for each item
Print the final total and percentages
As in Lab #1, 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 file that will be given below 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 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.
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
Schou, Sandra
A
450.00
35
65
3
1992
2004
450.00
Mother and Child
Williams, Mildred
A
200.00
85
40
2
1963
1999
0.00
Emerald Vase
de Tirtoff, Romain (Erte)
I
22000.00
22
18
2
Grading scale:
Code: (72%)
Correct recursive procedure to calculate Insured_value
and Expected_appreciation (20 points)
Correct declaration of struct type (8 points)
Correct use of array of structs (8 points)
Correct use/reuse of switch (5 points)
Correct use of input file (12 points)
Correct comparisons of Insured_value and
Expected_appreciation (7 points)
Good Programming Practices (12 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 - tasks 3 and 4 (16 points)
Output (can be more than one
session of running the program)
contains all the sample data and at least 5 more additional input
values (12 points)