Here are the rules that must be followed to verify a date. month of 1, 3, 5, 7,
ID: 3617620 • Letter: H
Question
Here are the rules that must be followed to verify a date.
month of 1, 3, 5, 7, 8, 10 and 12 must have days between1-31
month of 4, 6, 9, and 11 must have days between 1-30
month of February, 2, has 28 days if it is NOT a leapyear
Year1996 1996 % 4 ==0 IS leap year
Year1991 1991 % 4 !=0 IS NOT leap year
A century year is always divisible by 4. It is leap year only ifit is also divisible by 400.
Year2000 2000 % 400 == 0 it IS aleap year
Year1400 1400 % 400 != 0 itis NOT a leap year
You should have three functions. The following are the suggestedprototypes:
void getDate( int&, int&,int&); // get month,day and year from user and store them
// in reference arguments sent by caller
int ckDate( int, int,int); // check date based on three int values sent by caller
// return an int indicating the status of the date
void displayMsg(int); // display a message based on the date status
Your ckDate function should return an integer value depending onthe status of the date being ckecked:
Value: 0 = Good Date
1 = Bad Year
2= Bad Month
3= Bad Day not 1-31
4= Bad Day not 1-30
5= Bad Day not 1-29
6= Bad Day not 1-28
Based on the return value of ckDate(), the corresponding messageis displayed by the displayMsg() function.
Note:
It is important to figure out the algorithm before coding. Whena program uses multiple functions, the algorithm is divided intolevels. If the main calls ckDate function, then the algorithm formain is simply call ckDate to check date and don’t needmention about how to check a date. The detail of how to check adate would be the algorithm of ckDate function. The analysis ofchapter 6 and 7 examples should be very helpful.
Do not use any globalvariables!
Use meaningful and convenient variable names, properindentation, appropriate comments, and good prompting messages. Youare graded on both correctness and program style.
Note, don’t enter the leading 0 in case month or day issingle digit, even the prompt asks for mm/dd/yyyy. Below is asample run:
Enter a date (mm/dd/yyyy): 1/2/1998
1/2/1998 - Good Date
Enter a date (mm/dd/yyyy): 14/2/2000
14/2/2000 - Bad Month
Enter a date (mm/dd/yyyy): 2/33/1100
2/33/1100 - Bad Day not 1-28
Enter a date (mm/dd/yyyy): Ctr+Z
Explanation / Answer
please rate - thanks sorry it has an extra function to check leapyear #include using namespace std; void getdate(int&,int&,int&,string); bool isLeapYear(int); int isValid(int , int , int ); void displayMsg(int ); int main() { int month,day,year,code; string date; coutdate; while(cin) {getdate(month,day,year,date); code=isValid(month,day,year); coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.