Question: Write a MATLAB function named ship() that calculates the cost of sending a package according to the following cost table: Service (0-0.5 lbs) (0.5-5 lbs)
Write a MATLAB function named ship() that calculates the cost of sending a package according to the following cost table:
Service (0-0.5 lbs) (0.5-5 lbs) (more than 5 lbs)
| Ground (G) | $0.70 | $1.18 + $0.42 for every additional 0.5 lb (or fraction) | $4.96 + $0.72 for every additional lb (or fraction) |
|---|---|---|---|
| Express (E) | $2.40 | $4.40 + $1.20 for every additional 0.5 lb (or fraction) | $15.20 + $1.80 for every additional lb (or fraction) |
| Overnight (O) | $12.20 | 18.60 + $4.80 for every additional 0.5 lb (or fraction) | $61.80 + $6.40 for every additional 1 lb (or fraction) |
The function shipping takes three inputs: order number, type of service and the weight of the package. The function returns thecost of shipping the package. Write a MATLAB script shipcalc.m which readsthefile shiporders.txtto get the details of the orders. In shiporders.txtthere are details of 10different orders: the first column is order number, the second column is weight of package and the third column is the type of service (1 for Ground, 2 for Express and 3 for Overnight). Call the function shipping()for each order, calculate the cost of shipping and display on the command window in the following format:
Order 1: The cost to ship 8.4 pounds using service type G is $7.30
Order 2: ...
Order 3: ...
Order 4: ...
Order 5: ..
Shiporders.txt reads:
1 0.25 2 2 5.75 3 3 2.94 1 4 7.65 2 5 0.12 2 6 1.25 1 7 3.94 3 8 1.37 1 9 4.26 3 10 11.84 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
