Answer:
Check the explanation
Step-by-step 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.
% input the weight of the package
W=input('enter the weight of the package in pounds: \\');
% initialize the cost, and surcharge for excess weight
cost=15;
surcharge15;
% weights more than 100 pounds are not accepted if >100
disp('Sorry, no package over 100 pounds is accepted.);
else
% calculate the cost for the weights up to 100 pounds
if W>2
% cost is $5 for each extra pound
Cost=cost+(W-2)* 5;
End
if W>70
% extra charge is considered for weights more than 70 pounds
cost = cost+surcharge;
end
fprintf('The total cost for sending %3.2f pounds weight is %5.2f dollars \\', W, cost)
end
Execute the code at the MATLAB command window for different weigh of the packages
Enter the weight of the package in pounds:
2
The total cost for sending 2.00 pounds weight is 15.00 dollars
Enter the weight of the package in pounds.
3.5
The total cost for sending 3.50 pounds weight is 22.50 dollars
Enter the weight of the package in pounds:
72
The total cost for sending 72.00 pounds weight is 380.00 dollars
Enter the weight of the package in pounds:
101
Sorry, no package over 100 pounds is accepted
Thus, the MATLAB code is written and executed.