Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The price for renting a car at a car rental company is according to the followin

ID: 3841193 • Letter: T

Question

The price for renting a car at a car rental company is according to the following schedule: Sedan SUV Duration of rent Daily Free Cost of Daily Free Cost of rate miles Additional rate miles Additional (per day) mile (per day) mile 1-6 days $79 80 $0.69 $84 80 $0.74 7-29 days $69 100 $0.59 $74 100 $0.64. 30 or more days $59 120 S049 $64 120 $0.54 Write a MATLAB program in a script file that calculates the cost of renting a car based on the shown price schedule. The program must ask the user to enter the type of car (Sedan or SUV), the number of days, and the number of miles driven. The program then displays the cost (rounded to cents) for the rent in a sentence that reads: "The cost of the rent is xxx where XXX is the cost value in Run the program three times for the following cases: (a) Sedan, 10 days, 769 miles. (b) SUV, 32 days, 4,056 miles. (c) Sedan, 3 days, 511 miles. Hint: Use a switch-case structure for the type of the car (Sedan SUV) with nested alternative if structure for the number of days and miles. Use printf 0 to display the text and data. The data should be displayed in f format with two decimal digits.

Explanation / Answer

Matlab Code:

car=input('Enter the car type: ','s');
days=input('Enter the number of days: ');
miles=input('Enter the number of miles driven: ');
cost=0.0;
switch car
case 'Sedan'
if(days >= 30)
cost = (days * 59);
if (miles - days*120)>0
cost =cost + (miles - days*120)*0.49;
end
elseif(days >= 7)
cost = (days * 69);
if (miles - days*100)>0
cost =cost + (miles - days*120)*0.59;
end
else
cost = days*79;
if (miles - days*80)>0
cost =cost + (miles - days*120)*0.69;
end
end   
case 'SUV'
if(days >= 30)
cost = (days * 64);
if (miles - days*120)>0
cost =cost + (miles - days*120)*0.54;
end
elseif(days >= 7)
cost = (days * 74);
if (miles - days*100)>0
cost =cost + (miles - days*120)*0.64;
end
else
cost = days*84;
if (miles - days*80)>0
cost =cost + (miles - days*120)*0.74;
end
end   
end
fprintf('The cost of the rent is %.2f $.',cost);

Output:

Enter the car type: Sedan
Enter the number of days: 10
Enter the number of miles driven: 769
The cost of the rent is 690.00 $.

Enter the car type: SUV
Enter the number of days: 32
Enter the number of miles driven: 4056
The cost of the rent is 2164.64 $.

Enter the car type: Sedan
Enter the number of days: 3
Enter the number of miles driven: 511
The cost of the rent is 341.19 $.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote