Important
THIS CODES ARE DEVELOPED BYLORENCE ISIDORO
Tip
THIS C++ CODE HAVE A SAME CODE EXAMPLE : they have the same code, they use Zeller's Congruence Algorithm, the only difference is in the if, else statement, just added a switch statement which is the months.
CALENDAR USING C++
Zeller's Congruence Algorithm
if, else statement
Basic C++ Project
Click here to view the Calendar if, else statement.docs
int DAYSINMONTH(int month, int year) {
if (month == 4 || month == 6 || month == 9 || month == 11) {
return 30;
} else if (month == 2) {
return ISLEAPYEAR(year) ? 29 : 28;
} else {
return 31;
}
}
int DAYSOFYEAR(int year, int month, int day) {
int DAYSINMONTH[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
year -= month < 3;
return (year + year / 4 - year / 100 + year / 400 + DAYSINMONTH[month - 1] + day) % 7;
}
CALENDAR USING C++
Zeller's Congruence Algorithm
if, else with Switch statement
Basic C++ Project
Click here to view the Calendar if, else with switch statement.docs
int DAYSINMONTH(int month, int year) {
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return 31;
case 4:
case 6:
case 9:
case 11:
return 30;
case 2:
return ISLEAPYEAR(year) ? 29 : 28;
default:
return 0;
}
}
int DAYSOFYEAR(int year, int month, int day) {
int DAYSINMONTH[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
year -= month < 3;
return (year + year / 4 - year / 100 + year / 400 + DAYSINMONTH[month - 1] + day) % 7;