#include #include #include #include "date.h" using namespace std; const int date::length[] { 0, //dummy, so that January will have subscript 1 31, //January 28, //February. Pretend there are no leap years. 31, //March 30, //April 31, //May 30, //June 31, //July 31, //August 30, //September 31, //October 30, //November 31 //December }; date::date(int m, int d, int y) : day(365 * y + d - 1) { for (int month {1}; month < m; ++month) { day += length[month]; } } date::date() //today's date { const auto now {chrono::system_clock::now()}; const time_t t {chrono::system_clock::to_time_t(now)}; const tm *const p {localtime(&t)}; day = 365 * (p->tm_year + 1900) + p->tm_yday; } void date::print() const { const int year {day / 365}; int dayOfYear {day % 365 + 1}; int month {1}; for (; dayOfYear > date::length[month]; ++month) { dayOfYear -= date::length[month]; } cout << month << "/" << dayOfYear << "/" << year; } //Added operators // equality bool operator==(const date& a, const date& b) { return a.day == b.day; } // less than bool operator<(const date& a, const date& b) { return a.day < b.day; } // += date& date::operator+=(int n) { day += n; return *this; } // prefix date& date::operator++() { *this += 1; return *this; } // postfix date date::operator++(int) { const date old {*this}; ++(*this); return old; }