Write in MATLAB ... 27. Write a program in a script file that calculates the cos
ID: 3682577 • Letter: W
Question
Write in MATLAB ...
27. Write a program in a script file that calculates the cost of shipping a package according to the following price schedule: Weight Type of 0-0.5 lb 0.5-5 lb More than 5 lb service Ground $0.70+ $1.18 $0.42 for every $4.96 $0.72 for every (5-7 days) oz additional 0.5 lb (or additional lb (or frac- fraction). tion). Express $2.40+ $4.40 $1.20 for every $15.20+$1.80 for every (3-4 days) $0.25/oz additional 0.5 lb (or additional lb (or frac- fraction). tion). overnight $12.20+ $18.60+$4.80 for every S61.80+$6.40 for every (One day) $0.80/oz additional 0.5 lb (or additional lb (or frac- fraction). tion). The program asks the user to enter the type of service (Ground, Express, or overnight) and the weight of the package (two numbers. First for number of pounds and second for number of ounces) The program then displays the cost for the shipment. Run the program three times for the following cases: (a Ground 2 lb 7 oz. (b Express 0 lb 7 oz. (c) overnight 5 lb 10 oz.Explanation / Answer
function price = calc(service,lb,oz)
price = 0
disp(lb)
disp(oz)
if strcmp(service, 'Ground')
>> two = 1.18
twoextra = 0.42
three = 4.96
threeextra = 0.72
elseif strcmp(service, 'Express')
>> two = 4.40
twoextra = 1.20
three = 15.20
threeextra = 1.80
elseif strcmp(service, 'Overnight')
>> two = 18.60
twoextra = 4.80
three = 61.80
threeextra = 6.40
end
if(lb == 0 && oz < 8)
price = one + oneextra*oz
elseif(lb<5)
price = two + twoextra*ceil((lb*16+oz-8)*1.0/8)
else
price = three + threeextra*ceil(((lb-5)*16+oz)*1.0/16)
end
end
disp(calc('Ground',2,7))
disp(calc('Express',0,7))
disp(calc('Overnight',5,10))
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.