Computers 'R Us has decided that the public is tired of graphical Web interfaces and longs for a simpler console-based order entry system. They have asked you to build a small prototype so they can test the concept.
For this trial version (i.e., assignment), you should build a program that accepts orders for Laptop computers, Zip drives, and blank Zip disks. The program should ask the user for the quantity of each item in the order, calculates the cost and weight of the items ordered, and finally calculates the shipping cost and total cost of the order.
In this section, for most homeworks, we'll provide a list some of the relevant concepts. Don't forget, however, that CS is a lot like math in that you can never afford to forget concepts you learned earlier in the course; every new homework and programming concept builds on previously learned ones. In addition, later in the quarter, determining which concepts you should apply might well be part of your homework.
In this homework, keep an eye out for...
#define
)
Your program should prompt the user to enter (in order) the number of laptops, Zip drives, and blank Zip disks in the order. After each quantity is entered, the program should print the quantity ordered, total price for those items, and weight of those items. At the end, the program should print the subtotal (price of all items ordered), total weight, shipping costs, and total cost of the order.
Your program should run just like the sample executable we have provided on the web. The computed numbers should be exactly the same. The spacing in the output doesn't have to be identical, but the order of the inputs and outputs and your computed numbers must match exactly. (When we can, we use automated scripts to test submitted programs, which is one reason that it is important that your program accepts input and produces output in the same order as the sample program. The other reason consistency is important is TA sanity when they grade dozens of programs.)
Note: The sample program contains assertions to check for valid input. Your program should also do this (see Programming Requirements, below) but, of course, the variable names displayed if an assertion fails in your code will be variable names from your program, which don't have to be the same as the ones in the sample program.
The cost of the order depends on the prices and shipping weights of the individual items, as follows.
Item | Price | Weight (lbs) |
Laptop computer | $2195.99 | 32.0 |
Zip drive | $129.95 | 4.5 |
10-pack blank Zip disks | $99.95 | 2.8 |
Single blank Zip disk | $14.95 | 0.2 |
Shipping costs are $0.40 per lb.
If the user orders 10 or more blank Zip
disks, the program should fill the order using as many 10-packs as possible,
then add in the cost and weight of the individual disks needed to complete the
order.
Programming Requirements
It is important that your program be well-written, as well as work correctly. Besides general guidelines like picking good variable names, there a few specific things that are required for this assignment.
#define
to give meaningful names to significant
constants. In particular, item prices and weights, and the cost of
shipping should be given names using #define
, not written
directly into expressions in your program.assert
to stop your program with an error message if
non-numeric values are entered as input, or if the user enters a negative
quantity for number of items ordered. In later assignments we'll
introduce better ways to handle errors in user input, but it is better to at
least terminate execution if the input is invalid, instead of continuing to
calculate using uninitialized or erroneous data values.if
,
while
, for
, etc.) in this assignment. The
program can be written using only input and output plus assignment
statements (and assert
). Even if you know how to use
conditionals or loops, it's a good exercise to see if you can solve the
problem without them.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 cannot 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.