#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; } } }