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

Problem 7: Write a function days in month.m to display the number of days in a g

ID: 3607421 • Letter: P

Question

Problem 7: Write a function days in month.m to display the number of days in a given month. The function should have the header: function days = days in month (month, leap) where the input month is an all-lower-case string denoting the first three letters of the month. The input leap has logical value (0 or 1) indicating the leap year. The output days displays the number of days in the input month. February has 28 days (29 days in leap year). The following months have 30 days: Ap, June, September and November. Other months have 31 days. In cases where the inputs are invalid, the output days should be the string 'Invalid inputs'. The function should include a description. Use nested switch statements. (a) Set p7a=evalc('help days in month') (b) Set p7b-days in month(jan',0) (c) Set p7c=days-in-month('feb',0) (d) Set p7d-days in month('feb',1) (e) Set p7e=days.in.month('apr.0) (f) Set p7 days-in-month('aug',1) (g) Set p7g-days in month('oct',0) (h) Set p7h days in month('nov',1) (i) Set p7i days in month('Dec',0

Explanation / Answer

MATLAB CODE:-

function days = days_in_month(month,leap)
if(month =='jan')
i=1;
else if(month == 'feb')
i=2;
else if(month=='mar')
i=3;
else if(month == 'apr')
i=4;
else if(month == 'may')
i=5;
else if(month == 'jun')
i=6;
else if(month == 'jul')
i=7;
else if(month == 'aug')
i=8;
else if(month == 'sep')
i=9;
else if(month == 'oct')
i=10;
else if(month == 'nov')
i=11;
else if(month == 'dec')
i=12;
end
end
end
end
end
end
end
end
end
end
end
end

switch(i)
case 1
days = 31;
  
case 2
if(leap == 0)
days = 28;
else if(leap == 1)
days =29;
end
end
  
case 3
days =31;
case 4
days =30;
case 5
days=31;
case 6
days =30
case 7
days =31
case 8
days =31;
case 9
days =30;
case 10
days = 31;
case 11
days =30;
case 12
days = 31;
otherwise
disp('Invalid data')
end