#include //for cout #include "date.h" using namespace std; //because invalid_argument and cout belong to namespace std const int date::length[] { 0, //dummy, so that January will have subscript 1 31, //January 28, //February. Pretend there are no leap years. 31, //March 30, //April 31, //May 30, //June 31, //July 31, //August 30, //September 31, //October 30, //November 31 //December }; //The constructor installs 3 valid values into a newborn date object, //or it throws an exception. //this is a pointer to the object being constructed, so //this->year is a data member belonging to the object being constructed. //Plain old year without the this-> is an argument of the constructor. date::date(int month, int day, int year) { this->year = year; if (month < 1 || month > 12) { throw invalid_argument("bad month"); } this->month = month; if (day < 1 || day > length[month]) { throw invalid_argument("bad day of the month"); } this->day = day; } void date::print() const //Can't change the date object. { cout << month << "/" << day << "/" << year; } void date::next(int n) //Can change the date struct. { for (int i {0}; i < n; ++i) { next(); //Call the other next function, the one with no argument } } void date::next() //Move this date one day into the future. { if (day < length[month]) { ++day; } else { day = 1; //Advance into the next month. if (month < 12) { ++month; } else { month = 1; //Advance into the next year. year; } } }