|
|
|
|
|
|
|
day++;
if (day > DaysInMonth(mo, yr))
{
day = 1;
mo++;
if (mo > 12)
{
mo = 1;
yr++;
}
}
}
//******************************************************************
int DaysInMonth( /* in */ int month,
/* in */ int year )
// Returns the number of days in month month, taking
// leap year into account
// Precondition:
// 1 <= month <= 12 && year > 1582
// Postcondition:
// Function value == number of days in month month
{
static int numDays[12] = // No. of days per month
{
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
if (month != 2)
return numDays[month1];
// It's February. Check for leap year
if ((year % 4 == 0 && year % 100 != 0) ||
year % 400 == 0)
return 29;
else
return 28;
} |
|
|
|
|
|
|
|
|
A date is a logical entity for which we now have developed an implementation. We have designed, implemented, and tested a date ADT that we (or any programmer) can use whenever we have a date as part of our program data. If we discover in the future that additional operations on a |
|
|
|
|
|