#include #include #include "leapdate.h" using namespace std; leapdate::leapdate(int initial_month, int initial_day, int initial_year) : date(initial_month, initial_day, initial_year) { if (initial_day > length()) { cerr << "bad day " << initial_month << "/" << initial_day << "/" << initial_year << "\n"; exit(EXIT_FAILURE); } } int leapdate::length() const { const int y = get_year(); bool is_leap; //uninitialized; true if this is a leap year if (y % 400 == 0) { //2000 and 2400 are leap years is_leap = true; } else if (y % 100 == 0) { //1700, 1800, 1900, and 2100 are not leap years is_leap = false; } else if (y % 4 == 0) { is_leap = true; } else { is_leap = false; } return !is_leap && get_month() == february ? 28 : date::length(); }