#include #include #include "date.h" using namespace std; const int date_length[] = { 0, //dummy element so that JANUARY will have subscript 1 31, //JANUARY 28, //FEBRUARY 31, //MARCH 30, //APRIL 31, //MAY 30, //JUNE 31, //JULY 31, //AUGUST 30, //SEPTEMBER 31, //OCTOBER 30, //NOVEMBER 31 //DECEMBER }; date::date(int initial_month, int initial_day, int initial_year) { if (initial_month < JANUARY || initial_month > DECEMBER) { cerr << "bad month " << initial_month << "/" << initial_day << "/" << initial_year << "\n"; exit(EXIT_FAILURE); } if (initial_day < 1 || initial_day > date_length[initial_month]) { cerr << "bad day " << initial_month << "/" << initial_day << "/" << initial_year << "\n"; exit(EXIT_FAILURE); } year = initial_year; month = initial_month; day = initial_day; } void date::next(int count) { div_t divide = div(count, 365); if (divide.rem < 0) { divide.rem += 365; --divide.quot; } year += divide.quot; day += divide.rem; while (day > date_length[month]) { day -= date_length[month]; if (++month > DECEMBER) { month = JANUARY; ++year; } } }