COSC 1320 - C++ Programming and
ITSE 1307 - Introduction to C++ Programming
Bob Comer, Professor of Computer Studies
Assignment 4 - Postal Packages
In the Gaddis textbook read Chapter 8 sections 8.1-8.10 and Chapter 9 section 9.1 before starting this assignment.
Lone Star Package Service ships packages within the state of Texas. Packages are accepted for shipping subject to the following restrictions:
For each transaction (package to be shipped), the user should enter the package weight followed by the 3 package dimensions in any order. The weight should be specified as a whole number of pounds and the dimensions are specified as a whole number of inches. Check to be sure that the user enters positive numbers for the package weight and dimensions. For transactions with invalid weight or dimensions, print an error message and skip the transaction.
The shipping charge is based on the following table. This table should be represented in your program as two one-dimensional arrays, one for the weight and one for the shipping charge. You can initialize the array elements in the array declarations using the values from the table below.
Weight |
Shipping Charge |
1 |
1.50 |
2 |
2.10 |
3 |
4.00 |
5 |
6.75 |
7 |
9.90 |
10 |
14.95 |
13 |
19.40 |
16 |
24.20 |
20 |
27.30 |
25 |
31.90 |
30 |
38.50 |
35 |
43.50 |
40 |
44.80 |
45 |
47.40 |
50 |
55.20 |
To determine the shipping charge, search the weight array for the package weight and then use the corresponding element from the shipping charge array. For example, the shipping charge for a 3 pound package would be $4.00. If the package weight falls between the weights in the weight table, use the larger weight. For example, the shipping charge for a 4 pound package would be 6.75. Do not hard code these values into your program code. For example, you should not have code like:
if ( packageWeight == 4 || packageWeight == 5) shippingCost = 6.75;
If you need a hint, check here:
Output
Write a shipping report in table (row and column) format. For each transaction, print:
After the transaction table, print the number of packages accepted for shipping and the number of packages rejected (do not count transactions where there is an input error).
Write the shipping report to a data file instead of the screen. Using an output file will allow you to create a neatly formatted output report that is separate from the input prompt messages. File input and output will be covered in detail later in this course (Chapter 14 in your textbook). Click here for a quick tutorial on creating an output file.
The screen dialog should look similar to this (user input is shown in bold):
For each transaction, enter package weight and 3 dimensions. |
The shipping report should look similar to this:
Trans Accept/Reject Weight Cost 1 Accepted 1 1.50 2 Accepted 7 9.90 3 Accepted 21 31.90 4 Accepted 45 47.40 5 Rejected 49 - 6 Rejected 25 - 7 Rejected 68 - 8 Accepted 50 55.20 9 Rejected 45 - Number of accepted packages: 5 Number of rejected packages: 4 |
Additional Requirements:
Copyright: 2005 by the Austin Community College
Department of Computer Studies. All rights reserved.
Comments to: Bob Comer
Last updated: August 25, 2005