In: Computer Science
Most Major airports have separate lots for long-term and short-term parking. The cost to park depends on the lot you select , and how long you stay. Considering this rate structure on the lot you select, and how long you stay. Consider this rate structure from the Salt Lake International Airport during the summer of 2016.
Long-Term (Economy) Parking
-The First Hour is $2.00, and each additional hour or fraction thereof is $1.00
-Daily maximum $9.00
-Weekly maximum $60
Short Term Parking
-The first 30 minutes are $2.00 and each additional 20 minutes or fraction thereof is $1.00
-Daily maximum $32.00
Write a program using matlab that asks the user the following:
-Which lot are you using?
-How many weeks, hours, days, and minutes did you park? Your program should calculate the parking bill.
Solution:
code:
lot=menu('Which lot do you want to park at?','Long-Term Lot','Short-term Lot');
disp('How long did you park in the lot?');
Weeks=input('Weeks:');
Days=input('Days:');
Hours=input('Hours:');
Minutes=input('Minutes:');
switch lot
case 1
bill=LongTermBill(Weeks,Days,Hours,Minutes);
case 2
bill=ShortTermBill(Weeks,Days,Hours,Minutes);
end
fprintf('Ticket Number\nTime Stayed:%3f Weeks %2f Days %2f Hours %2f Minutes\nFee: %4f Dollars\n',Weeks,Days,Hours,Minutes,bill);
LongTermBill.m
function result=LongTermBill(w,d,h,m)
% Makes the calculation the Long-Term Bill
hours=h+(m/60); %adds hours and minutes
hours=ceil(hours);%rounds to the nearest hour
if(hours>=6)
LTbill=(42*w)+(6*d)+6; %adds the total bill
else
LTbill=(42*w)+(6*d)+hours; %adds the total bill
result=Thebill
end
ShortTermBill.m
function result=ShortTermBill(w,d,h,m)
% Makes the calculation the Short-Term Bill
minutes=((h*60)+m)-30);
MinutesPrice=minutes/20;
MinutesPrice=ceil(MinutesPrice);
WeekPrice=7*25; %price to stay in st parking for a week
if(MinutesPrice>=25)
STbill=(WeekPrice*w)+(25*d)+25; % adds the total bill
else
STbill=(WeekPrice*w)+(25*d)+MinutesPrice; %adds the total bill
result=STbill;
end
Hit the thumbs up if you liked the answer. :)