/******************************************************************************************** date.h ********************************************************************************************/ #include <iostream> using namespace std; //class definition class Date { private: int year; // 0-???? int month; // 0-11 --> prints or returns 1-12 int day; // 0-29 --> prints or returns 1-30 static char separator; //holds the separator for all objects public: Date(const int m=1, const int d=1, const int y=1980); //constructor with inits //------- Print/Display routines ------- void setSeparator(const char& c = '/') { separator = c; } void print(ostream& out = cout) const; friend ostream& operator<<(ostream&, const Date&); //------- Inspect (look at) the individual member data ------- int getYear() const { return year; } int getMonth() const { return month + 1; } int getDay() const { return day + 1; } //------- Add to specific data members ------- void addYear(const int y) { if (y > 0) year += y; } void addMonth(const int m) { if (m > 0) { int sum = month + m; addYear(sum/12); month = sum % 12; } } void addDay(const int d) { if (d > 0) { int sum = day + d; addMonth(sum/30); day = sum % 30; } } //------- Add two of the same type together ------- void addDate(const Date& D) { addYear(D.year); addMonth(D.month); addDay(D.day); } Date operator+(const Date& D) const { Date temp = D; temp.addYear(year); temp.addMonth(month); temp.addDay(day); return temp; } };