/******************************************************************************************** date.cpp ********************************************************************************************/ #include "date.h" #include <iostream> using namespace std; /* Because it's a royal pain in the neck to do the 1-12 and 1-30 sequence without going into a bunch of if/else stuff, I just decided to STORE the day and month as if they were running from 0 to X. The print routine simply adds one to the stored value to get "the real thing" */ char Date::separator='/'; //------- Enhanced Default Constructor ------- Date::Date(const int m, const int d, const int y) { if ((d > 0) && (d <= 30)) day = d - 1 ; else day = 0; if ((m > 0) && (m <= 12)) month = m - 1; else month = 0; if (y > 0) year = y; else year = 1980; } //------- Print the object in "pretty" format ------- void Date::print(ostream& out) const { if (month < 9) out << '0'; out << month + 1 << separator; if (day < 9) out << '0'; out << day + 1 << separator; if (year < 1000) out << '0'; if (year < 100) out << '0'; if (year < 10) out << '0'; out << year; }; ostream& operator<<(ostream& out, const Date& D) { D.print(out); return out; }