Answer:
Check the explanation
Explanation:
The MATLAB program should follow the following condition:
- • $15.00 for first two pounds and $5.00 for each over two pounds.
- • If package is more than 70 pounds, extra $15.00 is added to the total cost.
- • The package more than 100 pounds are not accepted.
Type the following MATLAB code to calculate the cost of mailing the package with th given conditions.
<em>% input the weight of the package </em>
<em>W=input('enter the weight of the package in pounds: \n'); </em>
<em>% initialize the cost, and surcharge for excess weight </em>
<em>cost=15; </em>
<em>surcharge15; </em>
<em>% weights more than 100 pounds are not accepted if >100 </em>
<em>disp('Sorry, no package over 100 pounds is accepted.); </em>
<em>else </em>
<em>% calculate the cost for the weights up to 100 pounds </em>
<em>if W>2 </em>
<em>% cost is $5 for each extra pound </em>
<em>Cost=cost+(W-2)* 5; </em>
<em>End </em>
<em>if W>70 </em>
<em>% extra charge is considered for weights more than 70 pounds </em>
<em>cost = cost+surcharge; </em>
<em>end </em>
<em>fprintf('The total cost for sending %3.2f pounds weight is %5.2f dollars \n', W, cost) </em>
<em>end </em>
<em />
Execute the code at the MATLAB command window for different weigh of the packages
<em>Enter the weight of the package in pounds: </em>
<em>2</em>
<em>The total cost for sending 2.00 pounds weight is 15.00 dollars </em>
<em>Enter the weight of the package in pounds. </em>
<em>3.5 </em>
<em>The total cost for sending 3.50 pounds weight is 22.50 dollars </em>
<em>Enter the weight of the package in pounds: </em>
<em>72 </em>
<em>The total cost for sending 72.00 pounds weight is 380.00 dollars </em>
<em>Enter the weight of the package in pounds: </em>
<em>101 </em>
<em>Sorry, no package over 100 pounds is accepted </em>
Thus, the MATLAB code is written and executed.