using Matlab Problem 2. Cost of Parking-Switch/Case structures (50 points) Richm
ID: 3799498 • Letter: U
Question
using Matlab
Problem 2. Cost of Parking-Switch/Case structures (50 points) Richmond International Airport has several options for parking and the cost of parking varies depending on which lot you are parked in and the amount of time you are parkedi Economy Daily Parking our Valet Parking Parking Parking Rate per 24 hours $24.00 $20.00 $12.00 $7.00 $1.00 $2.00 Rate per Hour, or $3.00 $2.00 fraction thereof The first 60 After first 24 minutes are free, hours otherwise normal rates apply 1 http:// www.flyrichmond.com/index.ph arking-directions Create a function called calculateParking that accepts 2 input variables, lot and time and outputs 1 variable, cost. The variable lot is a string and can be 'economy' daily, hourly', or 'valet'. The variable time represents the number of hours parked. Use a switch/case structure to evaluate, based on the lot the user is parking in, what the 24-hour rate and hourly rate is. Then use iflelse structure(s) to determine whether the 24-hour rate or the hourly rate should be applied. Hint: Use the floor or ceil rounding functions to round up or down. Use the mod function to find the remainder, or modulus, in order to find the number of hours after a new day has passed.Explanation / Answer
Following is the required matlab code
function [cost] = calculateParking( lot, time )
time1 = time;
days = floor(time/24);
time = time - 24*days;
cost = 0;
switch lot
case 'economy'
cost1 = days*7.0 + time*1.0;
cost2 = time1*1.0;
cost3 = (days+1)*7.0;
cost = min( min( cost1, cost2 ), cost3);
case 'daily'
cost1 = days*12.0 + time*3.0;
cost2 = time1*3.0;
cost3 = (days+1)*12.0;
cost = min( min( cost1, cost2 ), cost3);
case 'hourly'
if time <= 1.0
time = 0.0;
end
cost1 = days*24.0 + time*1.0;
cost2 = time1*1.0;
cost3 = (days+1)*24.0;
cost = min( min( cost1, cost2 ), cost3);
case 'valet'
cost1 = days*20.0 + time*2.0;
cost2 = time1*2.0;
cost3 = (days+1)*20.0;
cost = min( min( cost1, cost2 ), cost3);
end
disp( cost );
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.