1st time trying to do C++. I need direction of how to write this program. Thank you.
Specification:
Follow the coding style guide lines of codingStyle.doc
A small postal system ships packages within your state. Acceptance of parcels is subject to the following constraints:
1. Parcels weight <= 50 pounds
2. The largest-dimension (length or width or height) <= 36 inches
3. The maxSize = (largest-dimension + girth) <= 72 inches. Girth is calculated as follows:
girth = 2 * ( length + width + height - largest-dimension)
If the parcel is accepted then the shipping charge is found by searching a lookup table consisting of 2 parallel arrays One array containing a weight values and a second array containing price values. If the weight falls between two weight values use the next higher weight in the table.
Build the lookup table by reading the values from the file parcel.rte into 2 parallel arrays. There will be an array of type int for the weight and an array of type float for the associated shipping cost.
Your program should process the transaction file, parcel.box, containing one record for each box mailed during the week. Each record contains a transaction number, followed by the weight and then 3 dimensions. The dimensions can be in any order. Your program should read a record for a parcel. Check for all the constraints. If it passes the constraint test then find the shipping cost from the lookup table. Use the function wt_index( ) to find the index of the matching parcel weight in the weight array. Then use this index to extract the shipping price from the cost array.
For each parcel record processed print a report line to the console. The line will contain the data from the transaction. If the parcel is accepted the last field will be the shipping cost. If rejected the last field will be the string "rejected"
Use this report format.
Transaction Weight Length Width Height Price
100 1 20 5 5 1.20
101 34 19 24 20 reject
You will need to use stream manipulators to make your report appear neat and readable.
At the end print a summary of the total number of parcels processed and the total which were rejected.
I have provided a the executable parcel.exe to use as an example of how your program should run.
Input: the input data are in two files:
'parcel.rte' lookup table
'parcel.box' parcel transactions
Building the lookup table:
The file 'parcel.rte' contains 25 pairs of values arranged as weight and shipping_cost. Read these values into 2 parallel arrays. The weight_array is type int and the shipping cost is type float. Your program will use this lookup table to determine the shipping cost of a parcel.
Transaction file:
I have provided some test data in the file 'parcel.box'. Each line is a transaction record. You must treat the file as “black box in that you do not know how many records are in the file.
Use a while(there are still records) loop to drive the process until EOF.
DO NOT STORE THE TRANSACTION FILE IN PARALLEL ARRAYS!! ('parcel.box')
I have provided the following function stubs for you to implement.
Your program logic should use these functions. You may add additional functions as needed by your design..
Required functions:
DO NOT CHANGE THE CALLING INTERFACE OF THESE FUNCTIONS
//---------------------------------------------------------------------------
int
girth(int length, int width, int height)
{
girth == 2 * ( length + width + height - largest_dimension)
note:girth() should use the function largest() to find the largest_dimension
return the girth
}
//---------------------------------------------------------------------------
// use this helper function to calculate girth
int
largest(int length, int width, int height)
{
return the largest of 3 values
}
//---------------------------------------------------------------------------
// use this function to help look up the shipping cost in the lookup table
// it is a standard linear search. Since the values are sorted you may
// also use binary search.
int
wt_index(int weightArray[], int arraySize, int boxWeight)
{
if the box_wt is an odd number increment to the next higner even weight
find box_wt in the array lookupWeight[]
return its index;
}
//---------------------------------------------------------------------------