THIS IS MATLAB CODE NOT JAVA PYTHON OR C++ plEASE HELP 1. The cost per mile for
ID: 3821394 • Letter: T
Question
THIS IS MATLAB CODE NOT JAVA PYTHON OR C++ plEASE HELP
1. The cost per mile for a rented vehicle is $ 1.00 for the first 50 miles, $0.75 for the next 200 miles, and $0.50 for all miles in excess of 250 miles. Write a MATLAB program (rentalcar,m) to determine the total cost for a user given number of miles.
2. Write a program that accepts a month and a year (both in numbers) from the user and prints out the number of days in that month. Background: There are 31 days in January, March, May, July, August, October, or December, and 30 days in April, June, September, or November. If the year is a leap year, February has 29 days, otherwise it has 28 days. Any year that is evenly divisible by 4 is a leap year. For example, 1988, 1992, and 1996 are leap years. However, there is still a small error that must be accounted for. To eliminate this error, a year that is evenly divisible by 100 (for example, 1900) is a leap year only if it is also evenly divisible by 400. For this reason, the following years are not leap years: 1700, 1800, 1900, 2100, 2200, 2300, 2500, 2600. This is because they are evenly divisible by 100 but not by 400. The following years are leap years: 1600, 2000, 2400. To determine if a number x is evenly divisible by another number y, in MATLAB, you can call a build-in function mod(x,y). If mod(x,y) is equal to 0, x is evenly divisible by y. For example, mod(1900, 100) is 0 and mod(1900,400) is 300
Explanation / Answer
1.miles = input('enter the miles : ');
cost=1
else if(miles<=200)
c=1*50+0.75*miles
else if(miles>=250)
c=1*50+0.75*200+0.5*miles;
disp(c);
2) input year=("enter year for which u want to calculate days");
input month=("enter the month for which u want to calaulate no. of days ");
if (year%4==0||year%400==0||year%4==0)
disp("this has 29 daya as this is a leap year")
else
{
switch(month)
case1:
nod=31
break;
case 2:
nod=30
break
case 3:
nod= 31;
break;
case 4:
nod=30;
// you can make cases like this for all the months and print particular number of days
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.