//interface file for a simple date class #ifndef DATE_H #define DATE_H #include using namespace std; #include // this provides != <= > >= when == and < using namespace std::rel_ops; // are defined // date class declaration class Date { public: Date (); // default constructor creates today Date(int yr, int mon, int day); // constructor - creates mon day, yr Date& operator= (int); // assign date with form yyyymmdd // input/output member methods void read(istream& iStr); // read a date // acceptable formats are // yyyy/mm/dd // yyyy-mm-dd // yyyy:mm:dd // a date may not contain any spaces void read(); // prompt for and read a date void print(ostream& oStr) const; // print in format yyyy/mm/dd void print() const; // print in format month dd, yyyy // to standard out // accessor functions int year() const; int month() const; int day () const; // increment & decrement functions Date operator++(); // add one day Pre-increment Date operator++(int); // add one day Post-increment Date operator--(); // subtract one day Pre-decrement Date operator--(int); // subtract one day Post-decrement void addYear(int=1); // add/sub years void addMonth(int=1); // add/sub months void addWeek(int=1); // add/sub weeks void addDay(int=1); // add/sub days // provide the == and < comparison overloads bool operator==(const Date&) const; bool operator<(const Date&) const; // static functions - for the class - not available to specific instances static bool leapYear(int yr); // is yr a leap year? static Date today(); // returns todays date static int daysIn(int month, int yr); // returns # of days in a month private: int yy, mm, dd; // data members // helper functions bool setDate(int yr, int mm, int day); // set the date to this day static bool validDate(int yr, int month, int day); // ensure validity // lowest valid year for this type of calendar static const int baseYear = 1582; }; // non-member insertion and extraction overloads istream& operator>>(istream&, Date&); ostream& operator<<(ostream&, const Date&); #endif