#include // class declaration class Date { private: int month; int day; int year; public: Date(int = 0, int = 0, int = 0); // constructor Date operator[](int); // overload the subscript operator void showdate(); // member function to display a date }; // implementation section Date::Date(int mm, int dd, int yyyy) { month = mm; day = dd; year = yyyy; } Date Date::operator[](int days) { Date temp; // a temporary date to store the result temp.day = day + days; // add the days temp.month = month; temp.year = year; while (temp.day > 30) // now adjust the months { temp.month++; temp.day -= 30; } while (temp.month > 12) // adjust the years { temp.year++; temp.month -= 12; } return temp; // the values in temp are returned } void Date::showdate() { cout << setfill('0') << setw(2) << month << '/' << setw(2) << day << '/' << setw(2) << year % 100; cout << endl; return; } int main() { Date a(4,1,1999), b; // declare two objects cout << "The initial date is "; a.showdate(); b = a[284]; // add in 284 days = 9 months and 14 days cout << "The new date is "; b.showdate(); return 0; }