This is based on chapter 8 #20 Matlab for Engineers by Holly Moore 5th edition.
ID: 3912729 • Letter: T
Question
This is based on chapter 8 #20 Matlab for Engineers by Holly Moore 5th edition.
Most Major airports have separate lots for long term an dshort -term parking. The cost to park depends on the logt 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.00
Short-term Parking
-The first 30 minutes are $2.00 and each additional 20 minutes or fractoin thereof is $1.00
- Daily maximum $32.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 bill.
You need to prompt the user and get input such as lot number, weeks, days, hours, and minutes from user
Example of the prompts as follow, after each prompt you need to get user input:
Enter 1 for long term or 2 for short term parking
Following prompts may depend on whether the user chose short term or long term parking
How many complete weeks did you park?
How many additional complete days did you park?
How many additional complete hours did you park?
How many additional minutes did you park?
Test cases:
Only positive integers will be used to test your program.
After user completes the required information, your program should tell the user how much is the cost.
Explanation / Answer
ScreenShort
--------------------------------------------------------------------------------------------
Program
%constant values initialized
longTermFHour=2.00;
longTermAddHour=1.00;
longTermDaymax=9.00;
longTermWkmax=60.00;
shortTermFHalf=2.00;
shortTermMin20=1.00;
shortTermDailyMax=32.00;
%user Prompt to enter type of lot
term=input("Enter 1 for long term 2 for short term parking Which lot are you using for:");
%if it is long term
if term==1
%prompt user details for week,day,hour and minute going to park
week=input("How many complete weeks did you park?");
days=input("How many additional complete days did you park?");
hrs=input("How many additional complete hours did you park?");
min=input("How many additional minutes did you park?");
%Calculate the cost aacording the conditions
total=(week*60)+(days*9);
hrs=hrs+(min/60);
if hrs<=1
total=total+2.00;
else
total=total+2.00+(hrs-1)*1;
end
%Display the cost
fprintf("Total Cost= $%.2f",total)
%if it is short term
elseif
%prompt user details for day,hour and minute going to park
days=input("How many additional complete days did you park?");
hrs=input("How many additional complete hours did you park?");
min=input("How many additional minutes did you park?");
%Calculate the cost aacording the conditions
total=(days*shortTermDailyMax);
min=hrs*60+min;
if min<=30
total=total+2.00;
elseif min>30 & min<=50
total=total+2.00+1.00;
else
total=total+2.00+1.00+(min-50)*(1/20);
end
%Display the cost
fprintf("Total Cost= $%.2f",total)
%Otherwise error message
else
fprintf("Wrong lot selection!!!")
end
----------------------------------------------------------------
Output
Enter 1 for long term
2 for short term parking
Which lot are you using for:1
How many complete weeks did you park?2
How many additional complete days did you park?4
How many additional complete hours did you park?2
How many additional minutes did you park?30
Total Cost= $159.50
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.