CSE 142 Homework #2
The two parts are relatively independent. However, it would be best to do
Part A first, as a warm for Part B. Completing the exercises will
give you experience
writing the functions you need for the programming assignment.
Exercises
The exercises are to complete the functions given in the program
below. The comments above each function specifies what it should do. Most of
the functions are given as "stubs", that is, with a header (prototype)
and a brain-dead return statement. For some functions, you may also have
to write the header portion. You are to complete the function in each case. You are *not* to
modify the main program. The main program provides a set of test
calls to the functions to test if your implementation is correct.
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.
Programming Assignment: Ordering Muggle Goods
The wizards were impressed
with your earlier work and have promoted you to the Muggle goods procurement
department. You will use what you
learned on your last project, as well as your new knowledge of conditionals and
functions, to design a program that assists in ordering supplies from the Muggle
world. Your program will generate order reports for items purchased from a
several suppliers.
In this homework, keep an eye out for
This is a simple program to create order forms based on a request for 6 items from
3 different suppliers. You can order Wormwood, Nettles, Snake fangs, Snails,
Porcupine quills, and Potion vials. These items have the following costs:
| Item No. |
Item |
Cost |
| 1 |
1 ounce Wormwood |
$6.50 |
| 2 |
1 ounce Nettles |
$3.99 |
| 3 |
1 Snake fang |
$24.99 |
| 4 |
1 Snail |
$13.25 |
| 5 |
1 Porcupine quill |
$2.99 |
| 6 |
1 Potion vial |
$10.50 |
Your program should request the
following as input:
- The number of ounces of Wormwood needed
- The number of ounces of Nettles needed
- The number of Snake fangs needed
- The number of Snails needed
- The number of Porcupine quills needed
- The number of Potion vials needed
Based on the values input above, your program will generate order requests to the
suppliers:
| Supplier No. |
Supplier |
Supplies |
| 1 |
California Dreams |
Wormwood, Nettles |
| 2 |
Parts R Us |
Snake fangs, Snails |
| 3 |
MalWart |
Potion vials, Porcupine quills |
Your program should generate the following output:
- If at least 1 item is ordered from a supplier, then an order request should be generated for that supplier.
- At most 1 order request per supplier will be printed.
- No order request will be printed if neither of the suppliers' items were desired.
- An order request should contain the following:
- The name of the supplier of the item(s)
- For each item ordered: the quantity, name, and cost of purchasing that many of the item
- The sub-total of this order
- Lastly, you should print the total cost of all orders
You will implement a few functions to help you generate the above order
requests:
- MakeOrder -- This function takes a supplier
number, an item number, the quantity for that item, and a second item
number and quantity. It will produce the order request for the intended
supplier and items. It returns the cost of the order. It will make use of
the following functions:
- printSupplierName -- This function takes a
supplier number and prints the name of the supplier corresponding to that supplier
number.
- printItemName -- This function takes an item
number and prints out the name of the item corresponding to that item
number
- PerItemCost -- This function takes an item
number and returns the cost of a single unit of that item.
We've provided a workspace and starter code to help you on your way,
including function definitions.
You will also want to download and run the sample PC executable and see some
sample runs of the program.
- Start early. Despite the fact that it improves your life immensely, so
many people ignore this advice. It always pays to get an early start.
- Read these instructions completely and carefully.
- Try running the sample executable with various input values.
- Before writing a single line of code, plan your solution on paper. Try
thinking about what you would do to perform the computations yourself.
- Develop and test the program a bit at a time. Don't
try to write the whole program and test it all at once. It is better to have a program that compiles and runs without
complete functionality, than a program that doesn't compile or run.
You should make good use of constants, conditionals,
and comments, and if-then-else
statements. Don't
forget the return statement in functions that return
values.
- Test your program thoroughly, comparing results with
the sample executable.
- Start right now!
Last updated: 01/30/2001 12:45 AM