CSE 142 Autumn 2000 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 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.


Lab Exercises (Due October 15)

The lab 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.

Sumission

Turn in part 2a using this web submission form.


Programming Assignment (Due October 22)


Introduction

The wizards were impressed with your earlier work and have promoted you to the muggle goods procurement department.  This department is responsible for purchasing goods in the muggle world, which can than be sold in stores in the magical world.   Goods are ordered (by mail order) from muggle suppliers and then distributed to the magical stores. Since the muggles know nothing about the magical world, the financial transactions are done in Euros. Information for transactions which take place in the magical world is reported in Galleons, Sickles, and Knuts.

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.

Key Concepts

In this homework, keep an eye out for...

Specifications

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:

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

Pricing

Here is the pricing information for each of the stores. Note that the shipping cost is a fixed charge which applies if goods are ordered from the store.

MalWart:

California Dreams:

Parts R Us:

Ye Olde Glasse Shoppe

Reports

You need to generate the following output:

Unit prices are calculated as follows:

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.

Programming Requirements

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:

Submission Guidelines

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.

Files


A few bits of advice

Announcements

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.


Return to main Homework page...