#include #include #include "date.h" using namespace std; int date::length() const { static const int a[] { 0, //dummy 31, //January 29, //February 31, //March 30, //April 31, //May 30, //June 31, //July 31, //August 30, //September 31, //October 30, //November 31 //December }; return a[month]; } void date::install(int m, int d, int y) { year = y; if (m < 1 || m > 12) { cerr << "bad month " << m << "/" << d << "/" << y << "\n"; exit(EXIT_FAILURE); } month = m; if (d < 1 || d > length()) { cerr << "bad day " << m << "/" << d << "/" << y << "\n"; exit(EXIT_FAILURE); } day = d; } date::date() //Initialize to the current date. { const time_t t {time(0)}; const tm *const s {localtime(&t)}; install(s->tm_mon + 1, s->tm_mday, s->tm_year + 1900); } date& date::operator++() { if (++day > length()) { day = 1; if (++month > 12) { month = 1; ++year; } } return *this; } date& date::operator--() { if (--day < 1) { if (--month < 1) { month = 12; --year; } day = length(); } return *this; }