Programming Requirements Write a C++ program that checks whether a date entered in the form of: month day year is a valid date. Note that the format is spaced using spaces. A valid date should satisfy the following: The year should be a value between 0 and 2020 inclusive The month value between 1 and 12 inclusive The day value should: Be between 1 and 30 for the months April, June, September, and November Be between 1 and 31 for the months January, March, May, July, August, October, and December Be between 1 and 29 if the year is a leap year, and 1 and 28 if it is not. A year can be a leap year based on the following: If the year is not the end of a century (e.g., 1994), the year should be a multiple of 4. If the year is the end of a century (e.g., 2000), the year should be a multiple 400. Example execution: ranger0$ ./checkDate < checkDate.dat 6 15 1988 is valid 11 -9 1992 is not valid 1 29 1991 is valid 2 29 1982 is not valid 1 20 1997 is valid 2 29 2000 is valid 2 29 1996 is valid 2 29 1994 is not valid 6 15 2970 is not valid -4 8 1953 is not valid 4 31 1999 is not valid 6 30 2000 is valid 5 31 2015 is valid 8 31 2019 is valid 12 31 2020 is valid 12 31 2018 is valid 11 1 2001 is valid 3 15 2014 is valid
Objectives
- Practice with I/O redirection
- Practice with conditional statements in C++
- Practice with loops in C++
Programming Requirements
Write a C++ program that checks whether a date entered in the form of:
month day year is a valid date. Note that the format is spaced using spaces. A valid date should satisfy the following:
- The year should be a value between 0 and 2020 inclusive
- The month value between 1 and 12 inclusive
- The day value should:
- Be between 1 and 30 for the months April, June, September, and November
- Be between 1 and 31 for the months January, March, May, July, August, October, and December
- Be between 1 and 29 if the year is a leap year, and 1 and 28 if it is not.
A year can be a leap year based on the following:
- If the year is not the end of a century (e.g., 1994), the year should be a multiple of 4.
- If the year is the end of a century (e.g., 2000), the year should be a multiple 400.
Example execution: ranger0$ ./checkDate < checkDate.dat 6 15 1988 is valid 11 -9 1992 is not valid 1 29 1991 is valid 2 29 1982 is not valid 1 20 1997 is valid 2 29 2000 is valid 2 29 1996 is valid 2 29 1994 is not valid 6 15 2970 is not valid -4 8 1953 is not valid 4 31 1999 is not valid 6 30 2000 is valid 5 31 2015 is valid 8 31 2019 is valid 12 31 2020 is valid 12 31 2018 is valid 11 1 2001 is valid 3 15 2014 is valid

Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 6 images









