Part A: Lab exercises | Part B: Magic Supplies Order Application |
web submission by 10:00 pm, Sunday, October 15, 2000 | web submission by 10:00 pm, Sunday, October 22, 2000 |
paper submission in lecture Monday, October 16, 2000, or in the homework drop box on the first floor of Sieg by 5:00 pm, Monday, October 16. | paper submission in lecture Monday, October 23, 2000, or in the homework drop box by 5:00 pm. |
The two parts are relatively independent. However, it would be best to do Part A first, as a warm for Part B. Completing the lab exercises will give you experience writing the functions you need for the programming assignment. It will also be good preparation for the midterm exam on Friday, October 13.
A sample solution is not provided, since when you compile the starting code, the test harness will print out the results of your functions. In order to get the program to compile, you will need to write a version of the function orderCheck which is syntactically correct.
Sumission
Turn in part 2a using this web submission form.
For this project, you need to write a program to assist in ordering supplies from the muggle world. This program will print information on the orders to be placed to the muggle stores, and will also print a price list telling what magical stores can charge for the goods ordered. You will need to combine what you learned in the previous project with conditional statements and functions. Read the entire assignment carefully, then create an outline of your solution before you begin to write code. Pay close attention to the specifications listed below.
In this homework, keep an eye out for...
This
program has three phases. First,
you will need to read in the quantities of various Muggle goods that you need to
order. Second, you need to print an
"order report" for each of the Muggle supplier from which you intend
to order. Finally, you need to
produce "price reports" by calculating and reporting the minimum price
you need to charge for the goods in order to break even.
The
first phase of your program is to read in the quantities needed of each item.
The Muggle goods for which you are responsible are: Wormwood, Nettles,
Snake fangs, Snails, Porcupine
quills, and Potion vials. Your
program should request as input:
The
number of ounces of Wormwood needed (read as a double)
The
number of ounces of Nettles needed (read as a double)
The
number of Snake fangs needed (read as an integer)
The
number of Snails needed (read as an integer)
The
number of Porcupine quills needed (read as an integer)
The
number of Potion vials needed (read as an integer)
There are four stores that you can order from: California Dreams, Parts R Us, Ye Olde Glasse Shoppe, and a the discount store MalWart. California Dreams is the only store that sells Wormwood and Nettles. Snake fangs, Snails, and Porcupine quills can be ordered from Parts R Us and Potion vials can be ordered from Ye Olde Glasse Shoppe. MalWart also sells Snake Fangs, Snails, Porcupine quills, and Potion Vials. If your order is large enough, you will place it from MalWart, otherwise you will buy from Parts R Us and/or Ye Olde Glass Shop.
Based
on the values read, you will need to determine if you can use MalWart, a volume
discounter. MalWart stocks Snake
fangs, Snails, Porcupine quills, and Potion vials.
In order to order from MalWart, you need to order goods from 3 or more of these
categories. In addition,
to order from MalWart, the total
quantity of Snake fangs, Snails, Porcupine quills, and Potion vials must be at
least 35. For example, 20 Snake
fangs and 20 Snails could not be ordered from MalWart but 20 Snake fangs, 20
Snails and 1 Porcupine quill could.
While reading these values, you need to check to determine if all inputs are valid. An input is invalid if it is less than 0. When you encounter a negative input, you should call the function ExitProgram (which we have written for you).
MalWart:
Shipping
80.00 (per order)
Snake
fangs 13.50
Snails
6.99
Porcupine
quills 14.99
per 8 (These can be ordered individually)
Potion
vials 11.25
California
Dreams:
Shipping
45.00 (per order)
Wormwood
6.29
Nettles
3.89
Parts
R Us:
Shipping
0.00 (free)
Snake
fangs 24.99
Snails
13.25
Porcupine
quills 2.29
Ye
Olde Glasse Shoppe
Shipping
35.00 (per order)
Potion
vials 20.50
(when ordering fewer than 12 Potion vials)
Potion
vials 11.35
(when ordering at least 12 Potion vials)
You
need to generate the following output:
If at least one item is ordered from a supplier, then you
need to generate an
order report.
You should generate at most one order report per supplier.
Every report (order reports and price reports) begins with a blank line followed
by a separator line; it ends with a separator line followed by a blank line.
After printing each report you should call WaitForAnyKeyToContinue().
An order report consists of:
The name of the supplier
Column headings
A separator line
The name of each good being ordered followed by its quantity
Do not display any good that is not being ordered (i.e., the quantity
is zero)
The price report consists of:
The title "Unit Cost Summary"
Column headings
A separator line
The name of each good being ordered followed by its cost in galleons,
sickles and knuts
Do not display any good that is not being ordered (i.e., the quantity is zero)
Do not display the price report if no goods are
ordered
Unit
prices are calculated as follows:
The shipping cost for a good is equal to the supplier's shipping cost
divided by the number of goods ordered from the supplier.
For example, if you order both Wormwood and Nettles from California
Dreams, the shipping cost for each is 22.50.
If you ordered Wormwood from California Dreams, but no Nettles, then
the shipping cost for Wormwood is 45.00
The base cost for a good is equal to the supplier's unit cost for that good,
multiplied by the quantity ordered.
The total cost for a good is the sum of the shipping cost and the base cost.
The unit cost for a good is the total cost, divided by the quantity ordered.
All costs are calculated in euros. This
needs to be converted to galleons, sickles and knuts before printing.
(There are 17 sickles in a galleon and 29 knuts in a sickle.
The value of the euro has risen since last project; there are 23.0
euros in a galleon.)
Make sure that instead of truncating the conversion from euros to galleons, sickles and knuts, you round the result up. (You might want to look at math.h in Appendix B of the textbook.)
You
should break the report-printing into a number of small functions. (You
are required to write and use these functions, even if you see other ways to
solve the problem)
1.
IsBulkOrder - Returns TRUE if you can order from MalWart.
(You should only call this function once, even though you may need the
result more than once.)
2.
PrintXXXOrder - Displays the order report for XXX. (You will need 4 such functions.)
3.
PrintHeader, PrintFooter, etc. - Prints those components of a report common to
all reports.
4.
PrintQuantity - Prints the quantity to be ordered (as a double).
The quantity should be aligned as in the sample solution.
5.
PrintXXXPrice - Displays the prices charged by XXX. (You will need 4 such functions.)
6.
CalculateUnitCost - Given the shipping cost, supplier unit price and quantity
returns the unit cost (in euros).
7.
PrintPrice - Given the price in euros, prints the equivalent value in wizard
money (each value printed as an integer).
The
sample executions serve as a guide for the expected output.
We have also saved you some time by starting you with some #defines.
One of the key concepts you should exercise in this assignment is appropriate use of functions. Some operations need to be performed several times (verifying that input is successful and that the input has a sensible value is one fairly obvious example). Other operations are sufficiently complex or subtle that it makes sense to define them as a function. That isolates the details of the operation in a separate part of the code instead of embedding it in in the main program.
You should define appropriate functions in your program and use them as needed. Some functions are explicitly mentioned in the instruction, and you are required to implement and use them. The rest replies on your own best judgement. You shouldn't define a tiny function for every separate calculation in the program, but you should use functions to break up the program into understandable chunks of code, each one of which does a single, self-contained operation.
Beside the specific requirement of using functions appropriately, your code should be clean and understandable as always. Remember to:
#define
to give meaningful names to significant
constants.if
) statements to
check for errors, and terminate the program
after printing an error message. Experiment with the sample program to
get an idea of what should happen.int
and double
(floating-point)
variables appropriately in your program.The due date for this assignment is at the top of this page. Be especially aware of the web submission deadline, as submission times are tracked precisely and we do not accept late submissions.
If any clarifications or changes need to be made for this homework, they will be posted to the cse142-announce email list and linked here.