169k views
0 votes
The cost of sending a package by an express delivery service is $15 for the first two pounds and $5 for each pound or fraction thereof over two pounds. If the package weighs more than 70 pounds, a $15 excess weight surcharge is added to the cost. No package over 100 pounds will be accepted. Write a program that accept the weight of a package in pounds and computes the cost of mailing the package. Be sure to handle the case of overweight package.

1 Answer

2 votes

Answer:

Check the explanation

Step-by-step explanation:

The MATLAB program should follow the following condition:

  1. • $15.00 for first two pounds and $5.00 for each over two pounds.
  2. • If package is more than 70 pounds, extra $15.00 is added to the total cost.
  3. • 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.

User JCQuintas
by
4.5k points