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

A basic class dateType is designed to implement the date in a program, but the m

ID: 3604854 • Letter: A

Question

A basic class dateType is designed to implement the date in a program, but the member function setDate does not check whether the date is in valid format. a. Rewrite the definition of the function setDate so that the values for the month (1 to 12), day (1 to 31), and year (4 digits) are checked before storing the date into the member variables. b. Add a member function, isLeapYear, to check whether a year is a leap year.

there should be three files, dateType.h dateTypeImp.cpp main.cpp

dateType.h

dateTypeImp.cpp

main.cpp

Explanation / Answer

First we implement isLeapYear() function so it can help us in setDate() function to check leap year.
Lets implement the function to check given year is Leap year or not.
Condition of leap year is as, If year is divisible by 4 with reminder 0 then its Leap year,
But if year is divisible by 4 and 100 with reminder 0 then we check it for does it divisible by 400 then only
ther year becomes Leap year.
So lets implement isLeapYear() function as follows,

bool dateType::isLeapYear() const
{
if(dYear%4 == 0) // here we check does year is divisible by 4
{
if(dYear%100 == 0) //here we check does year is divisible by 100
{
if(dYear%400 == 0) // when year is leap year only if it is divisible by 100 and 400
{
return true;
}
}
return true;
}
return false;

}

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