1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
bool isLeapYear(int year) {
return (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0));
}
bool isGregorianDate(int month, int day, int year) {
{
if (year < 1752)
return false;
if ((year == 1752) && (month < 9))
return false;
if ((month == 9) && (day < 13))
return false;
return true;
}
}
bool isValidDate(int month, int day, int year) {
if (month > 12) {
return false;
}
if (month < 1) {
return false;
}
if (day < 1) {
return false;
}
if (day > 31) {
return false;
}
if (((isGregorianDate) && ((month = 1 || 3 || 5 || 7 || 8 || 10 || 12)
&& ((day >= 1) && (day <= 31)))) || ((isGregorianDate) && ((month =
4 || 6 || 9 || 11) && ((day >= 1) && (day <= 30)))) || ((isGregorianDate) &&
((month = 2) && ((day >= 1) && (day <= 28)))) || ((isGregorianDate) &&
(isLeapYear) && ((month = 2) && ((day >= 1) && (day <= 29))))) {
return true;
}
}
static void test_isValidDate() {
cout << "Testing -- isValidDate()" << endl;
cout << isGregorianDate(8, 19, 2016) << " PROPER INPUT---correct value is: 1" << endl;
cout << isGregorianDate(3, 12, 1234) << " PROPER INPUT---correct value is: 0" << endl;
cout << isGregorianDate(1, 1, 2000000) << " PROPER INPUT---correct value is: 1" << endl;
cout << isGregorianDate(1, 1, 1) << " PROPER INPUT---correct value is: 0" << endl;
cout << isGregorianDate(1, 1, -10) << " PROPER INPUT---correct value is: 0" << endl;
cout << isGregorianDate(1, 1, -2000000) << " PROPER INPUT---correct value is: 0" << endl;
cout << isGregorianDate(13, 1, 2000) << " IMPROPER INPUT---correct value is: 0" << endl;
cout << isGregorianDate(1, 40, 2000) << " IMPROPER INPUT---correct value is: 0" << endl;
cout << isGregorianDate(-1, 1, 2000) << " IMPROPER INPUT---correct value is: 0" << endl;
cout << isGregorianDate(1, -1, 2000) << " IMPROPER INPUT---correct value is: 0" << endl;
cout << "Finished testing -- isValidDate()" << endl << endl;
}
|