Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++. Program 7 - Postal Packages Lone Star Package Service ships packages within the state of Texas. Packages are accepted for shipping subject to the

C++. Program 7 - Postal Packages

Lone Star Package Service ships packages within the state of Texas. Packages are accepted for shipping subject to the following restrictions:

Shipping requirements

The package weight must not exceed 50 pounds. The package must not exceed 3 feet in length, width, or height. The girth of the package must not exceed 5 feet. The girth is the circumference around the two smallest sides of the package. If side1, side2, and side3 are the lengths of the three sides, and largest is the largest of the three sides, then the girth can be calculated using: girth = 2 * ( side1 + side2 + side3 - largest ) 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.

To end the program, the user should enter a weight of -1. When the user enters -1 to end the program, they should not have to enter values for the 3 package dimensions. That is, when the user is ready to end the program, they should only have to enter the weight:

Enter package weight and 3 dimensions: -1

They should not have to enter:

Enter package weight and 3 dimensions: -1 0 0 0 Input Validation

Check to be sure that the user enters positive numbers for the package weight and dimensions (weight and dimensions must be larger than zero). 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 may be represented in your program as parallel arrays (two one-dimensional arrays), one for the weight and one for the shipping charge. Alternatively, you may define a struct or simple class to represent one table entry (one weight and cost). Then the table would be an array of structs or an array of objects.

Note: Do not use a two-dimensional array to store the weights and costs. The weights need to be stored as integers, and the costs need to be stored as floating-point values. So they cannot be mixed in one array.

You can initialize the array elements in the array declarations using the values from the table below:

image text in transcribed

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;

Output

Note that you should be able to write this program with only two loops, a transaction processing loop and a cost search loop. You do not need an input validation loop. If the package input is invalid, just print an error message and skip the normal package processing.

I want you to input the package information, process the package and output some information about the package in a single loop (the transaction processing loop).

Your program output should look similar to the example below.

Note: Do not store the package information in an array or vector. If you process a lot of packages, you will eventually run out of space in the array. If you use a vector, as you process more transactions you will eat up more and more memory. This program should be designed to run for long periods of time without running out of memory.

For each transaction, print:

*the transaction number (start counting with 1) *whether the package was accepted or rejected *the package weight *the costfor shipping (if applicable) *When the program ends, print the number of packages accepted for shipping and the number of packages rejected. Transactions that contain invalid input should not be counted (see Input Validation section).

The screen dialog should look similar to this (user input is shown in bold):

image text in transcribed

image text in transcribed

Additional Requirements:

1)Do not use global variables in any assignment. A global variable is a variable that is declared outside any function. It is okay to use global constants. 2)You must use multiple functions in this program. Do not write the program as one large main function. 3)Do not store the transaction information in arrays or vectors. When you store transactions in arrays, you set a limit on the number of transactions your program can process. For this program, you should be able to read and process transactions one at a time.

Weight Shipping Charge 10 13 16 20 25 30 35 40 45 50 1.50 2.10 4.00 6.75 9.90 14.95 19.40 24.20 27.30 31.90 38.50 43.50 44.80 47.40 55.20

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions