#ifndef DATEH #define DATEH #include using namespace std; class date { static const int length[]; int year; int month; //date::january to date::december inclusive int day; //1 to length[month] inclusive public: enum month_t { //indices into the length array january = 1, february, march, april, may, june, july, august, september, october, november, december }; //Exceptions thrown by the member functions of class date: class bad_month { const int month; public: bad_month(int initial_month): month(initial_month) {} friend ostream& operator<<(ostream& ost, const bad_month& bm) { return ost << "bad month " << bm.month; } }; class bad_month_and_day { const int month; const int day; public: bad_month_and_day(int initial_month, int initial_day) : month(initial_month), day(initial_day) {} friend ostream& operator<<(ostream& ost, const bad_month_and_day& bd) { return ost << "bad month " << bd.month << ", day " << bd.day; } }; class overflow {}; class underflow {}; date(int initial_month, int initial_day, int initial_year) throw (bad_month, bad_month_and_day); date& operator++() throw (overflow); date& operator--() throw (underflow); const date operator++(int) throw (overflow) { const date old = *this; ++*this; //(*this).operator++(); return old; } const date operator--(int) throw (underflow) { const date old = *this; --*this; //(*this).operator--(); return old; } friend ostream& operator<<(ostream& ost, const date& d) { return ost << d.month << "/" << d.day << "/" << d.year; } }; inline ostream& operator<<(ostream& ost, const date::overflow&) { return ost << "can't go beyond December 31, " << INT_MAX; } inline ostream& operator<<(ostream& ost, const date::underflow&) { return ost << "Can't go before January 1, " << INT_MIN; } #endif