E7_Su2010_Solutions3_all

# E7_Su2010_Solutions3_all - Assigned October 2 Fall 2009 Due...

This preview shows pages 1–3. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Assigned: October 2 Fall 2009 Due: October 14 9 case ’wednesday’ 10 num = 4; 11 case ’thursday’ 12 num = 5; 13 case ’friday’ 14 num = 6; 15 case ’saturday’ 16 num = 7; 17 otherwise 18 num = NaN; 19 end 20 21 >> Day2Num(’tUesDay’) 22 ans = 23 3 end code (b) Write a function with the header line function totaldays = DaysInMonth(month,year) using if statements, relational operators, and strcmp that will take two arguments, month and year , and return the numbers of days in the month of that year. Your function should be able to compute leap years where the month of February will return 29 days. In addition, your function should be able to return the appropriate number regardless of the letter casing in month . If month is misspelled, return NaN . (Hint: look up leap year in Wikipedia to determine the formula that will calculate which years are leap years) Solution: begin code 1 % Solution 1 2 function totaldays=DaysInMonth(month, year) 3 month = lower(month); 4 if (strcmp(month,’january’) | strcmp(month,’march’) |...
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern