Professional Documents
Culture Documents
5. Implement in C++ the following PDL program (developed for Homework #4) that reads in a
distance in miles, then calculates and displays the shipping cost.
produceShippingCost
local totalShippingCost
local const fixedShipmentCost = 50
proc calculateVariableCost //calculate part of the cost that varies with the distance
if ( shippingDistance ≤ 100) then //distance ≤ 100
//£5 per mile
set variableShippingCost to (5 * shippingDistance)
else //distance > 100
if ( shippingDistance ≤ 500) then //distance > 100 and distance ≤ 500
//£5 for each of first 100 miles, £4 for remaining miles
set variableShippingCost to ( (5 * 100)
+ (4 * (shippingDistance - 100)) )
else //distance > 500
//£5 for first 100 miles, £4 for next 400 miles, £3 for remaining distance
set variableShippingCost to ( (5 * 100)
+ (4 * 400)
+ (3 * (shippingDistance - 500)) )
endif
endif
endproc
Format the program's outputs so that it shows the cost in the usual currency format, e.g.,
You do not have to check the validity of the type of the input (i.e. you can assume that the user
will only enter a number for the distance).
Look at section 3.4 in the C++ notes & refer to tutorial sheet # 4 to find out how to format the
output for currency (£ sign and numbers representing pounds and pence).