Note: MATLAB has a menu function that generates a menu of choices for user input
ID: 3869912 • Letter: N
Question
Note: MATLAB has a menu function that generates a menu of choices for user input. An example of the use of this function is the following code choice = menu ( ' Choose a color ' , ' Red' , ' Blue ' , ' Green' ) The number entered by the user in response to the prompt is returned as choice (i.e choice 2 implies that the user selected Blue). Practice the use of menu function Problem 1 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. Consider this rate structure from an International airport during September 2017 Long-Term Lot o The first hour is $1.00, and each additional hour or fraction thereof is $1.00 o Daily maximum $6.00 o Weekly maximum $42.00 Short-Term Lot The first 30 minutes are free and each additional 20 minutes or fraction thereof is $1.00 o o Daily maximum $25.00 Write a program that asks the user the following .Which lot are you using? How many weeks, hours, days, and minutes did you park? Your program should then calculate the parking billExplanation / Answer
function CostCal
choice=menu('choose a option','Long-Term Lot','Sort-Term Lot');
prompt='how many week:';
week=input(prompt);
prompt='how many days:';
day=input(prompt);
prompt='how many hours:';
hours=input(prompt);
cost=0;
if choice==1
cost=hours;
if(cost>6)
fprintf('exceed daily limit');
return;
end
cost=cost*day;
cost=cost*week;
if(cost>42)
fprintf('weekly limit exceed');
return;
end
end
if choice==2
hours=hours*60-30;
hours=hours/(20);
cost=hours;
if(cost>25)
fprintf('exceed daily limit');
return;
end
cost=cost*day;
cost=cost*week;
end
fprintf('Total bill :%g ',cost);
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.