Lab Assignment # 2, CSE 1320
Sections 001 and 501, Fall 2004
Due Date: Section 501 – Oct 19th, 5:30 pm
Section 001 –Oct 20th, 1:00 pm.
(see instructions on website for how to turn this in)
[Clarifications added Oct 12th are highlighted in yellow throughout lab]
Topic objectives: Pointers and dynamic memory space allocation
Strings and string functions
Arrays of pointers
More control structures
Functions, parameter passing, side effects
Modular design
Well, after working through your financial simulation you have decided to go ahead and start planning the details for your bookstore, Plus or Minus Perfect Books (or ‘±Perfect’ for short). You’ve decided that the first things you should do would be to finalize the categories of books you will carry, select a few prominent new titles for each category, and start communicating with publishers and distributors to develop the process you will use to stock your store once it gets started. You will be using potential customers to help decide on categories and titles and you will make decisions about publishers/distributors based on cost and availability information they supply.
In order to accomplish all this your program will do the following tasks. First, the program will accept at least 3 but no more than 10 categories of books to be sold in the store. The category names will be read in from the user as strings and the strings will be referenced by pointers in an array. Once the user has entered all the categories they want, then for each category the program must have the user enter two titles of books that will be used to compare publishers and distributors. For each book, the user will enter a title, an author’s last name, a retail price, and a quantity. The title and author will be stored as arrays of strings and retail price and quantity stored in numeric arrays like in the financial simulation lab. The following are the tasks you must do:
After the user has entered books for each category then the program will begin the decision making process for publishers/distributors. In this stage the program will be querying the user for data from a particular publisher/distributor about all of the entered books. The program must find out from each publisher/distributor how much the wholesale price is for each book in the bookstore and how many copies of the book are available from the publisher/distributor of that book. This data is collected for every book that was entered previously. When all of the data for a single publisher/distributor has been collated, the program must ask the user if they wish to do the same for another publisher/distributor until the data for all potential publishers/distributors has been entered. Then the program will make recommendations based on the publisher/distributor information as to which company or companies you, ±Perfect Books, should use.
i.
For
each book with availability over 140%, change the book percentage to 140%
ii. Add all the book availability percentages and divide by the number of books to get the percentage of total requested quantity for that publisher/distributor.
i.
For
each book calculate the book profit as
bookprofit = (retail price – wholesale
price) * requested book amount;
Then after each books values
have been calculated for a publisher/distributor:
ii.
For
each publisher/distributor calculate grossprofit as
grossprofit = sum the all bookprofits
for that publisher/distributor ;
iii.
For
each publisher/distributor calculate percentage profit as
percprofit = ( grossprofit / cost of a wholesale order (part a. above) ) * 100 ;
i. Less than 25% profit
ii. Between 25% and 50% profit
iii. Between 50% and 75% profit
iv. Between 75% and 100% profit
v. Over 100% profit
After this is done, print a concluding message and then end the program.
Implementation
requirements:
The program should use the following data structures:
Integer and floating point arrays as described above
Arrays of pointers to char for referencing strings
Buffers for reading in strings (either char arrays or malloc’d space)
The program should NOT use the following data structures:
structs
The program should use the following control structures:
Switch statements to perform the tasks in parts 10b and 10c
Loops and 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 have a main function and at least four
(4) subfunctions but no more than twelve (12) subfunctions. Each function should focus on one particular
task.
This program must be run with at least two different sets of data. The first data set (data set 1) should use the values given below. You must also create at least one additional data set and run your program with it as well. You must execute the program two different times so that you have a total of at least two different data sets. The sample data sets that you create must meet the guidelines given in the problem definition.
Category Book title Author Retail Quantity
Mystery: “Shattered” Francis 24.95 10
Mystery: “God Bless John Wayne” Friedman 6.00 5
Sci-fi: “I, Robot” Asimov 7.99 250
Sci-fi: “Monstrous Regiment” Pratchett 22.49 15
Self-help: “Life and How to Survive It” Cleese 12.00 20
Self-help: “How to Ruin Your Life” Stein 12.95 2
Publisher/distributor name Book title Wholesale Available
Amazon “Shattered” 9.99 90
Amazon “God Bless John Wayne” 4.00 25
Amazon “I, Robot” 2.00 2000
Amazon “Monstrous Regiment” 16.99 12
Amazon “Life and How to Survive It” 10.00 100
Amazon “How to Ruin Your Life” 5.00 250
Barbie “Shattered” 19.99 100
Barbie “God Bless John Wayne” 4.50 100
Barbie “I, Robot” 2.50 100
Barbie “Monstrous Regiment” 12.99 100
Barbie “Life and How to Survive It” 7.50 100
Barbie “How to Ruin Your Life” 15.00 100
Campbell “Shattered” 15.00 10
Campbell “God Bless John Wayne” 6.00 0
Campbell “I, Robot” 6.00 10
Campbell “Monstrous Regiment” 15.00 100
Campbell “Life and How to Survive It” 6.00 10
Campbell “How to Ruin Your Life” 6.00 100
Dumble “Shattered” 10.00 1000
Dumble “God Bless John Wayne” 3.00 5000
Dumble “I, Robot” 3.00 5000
Dumble “Monstrous Regiment” 10.00 1000
Dumble “Life and How to Survive It” 3.00 5000
Dumble “How to Ruin Your Life” 3.00 5000
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 value from the keyboard
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.
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: (78%)
Headers, Style, Modularity (20 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 strings including
pointer declaration and dynamic memory allocation (12 points)
Correct manipulation of the arrays of
pointers (10 points)
Correct use of required control structures (6
points)
Correct function structure as required (5 points)
Each task performs mathematically correctly (6 points per task 9a., 9b, 9c.)
Proper implementation of input and user control (7 points)
Output: (22%)
User clearly understands what is being requested for input (6 points)
Output gives clear information to explain the values to the user (6 points)
Output contains all the sample
data and at least one additional data set
(10 points)
Deductions:
Use of structs will result in a 10
point deduction
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 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.