#include "stdstuff.h" #include "Date.h" void realMain () { Date d, d2; int days; char day_names [][10] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" }; // If the following is included, the constructor will throw an exception. // Date dummy (-1, -1, -1); for (;;) { cout << "Enter dd mm yyyy (invalid values to terminate): "; d.read (cin); if (cin.fail()) { return; } cout << "Enter days to move date forward (may be -ve): "; cin >> days; try { d.move (days); cout << "The new date is "; d.write (cout); cout << ". That is a " << day_names[d.dayInWeek()- 1] << ".\n"; } catch (invalid_argument &e) { cout << "Date not moved - new date would be outside valid range.\n"; cout << "The date is still "; d.write (cout); cout << endl; } // a simple example of using a function which returns a date d2 = d.nextDay(); cout << "The day after that is "; d2.write(cout); cout << endl; // a trickier way of doing the same thing cout << "The day after that is "; d.nextDay().write(cout); cout << endl; cout << "Comparing that day with the next day produces " << d.compareTo(d.nextDay()) << endl; } } int main () { try { realMain (); } catch (exception &e) { // catches all uncaught exceptions cout << "\nException <" << e.what() << "> occurred.\n"; } pause (); return 0; }