Answered step by step
Verified Expert Solution
Question
1 Approved Answer
c + + Write a method / function called daysInMonth ( ) that takes in a month ( as an integer ) and an integer
c Write a methodfunction called daysInMonth that takes in a month as an integer and an integer year as parameters and returns the number of days in that month as an integer. For example the call daysInMonth should return as there are days in January
If the user inputs a day in Feburary make sure to account for the possibility of a leap year.
Rules for leap years are:
If a year is divisible by it must also be divisible by to be a leap year. For example, is a leap year and is not a leap year.
If a year is not divisible by it must be divisible by to be a leap year. For example, is a leap year and is not a leap year.
If the user types in a month that doesn't exist return as an error message. Do the same for any year that is less than
After you have written the method, write a main program that demonstrates the use of your method in at least different ways showing that it works. Include at least one error case.
Hint: Using a switchstatement and its fallthrough feature is much easier than using an ifelse statement!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started