Date& operator++(){ //add 1 to d //tomorrow, unless we were at the end of the mo
ID: 3652336 • Letter: D
Question
Date& operator++(){//add 1 to d //tomorrow, unless we were at the end of the month
//if is_date is false
// //need to change to first of next month
// set d to 1
// if m is December
// //need to change to next year too
// set m to January
// increment y
// else
// increment m
return *this;
}
Write a main function which repeatedly reads a Date with
cin >>, increments the Date with your ++, and prints "Tomorrow is" and the
new value of the Date using cout <<.
//Chrono.h
namespace Chrono {
Class Date {
public:
enum Month {
jan=1, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec
};
class Invalid { }; // to throw as exception
Date(int y, Month m, int d); // check for valid date and initialize
Date(); // default constructor
// the default copy operations are fine
// non-modifying operations:
int day() const { return d; }
Month month() const { return m; }
int year() const { return y; }
// modifying operations:
void add_day(int n);
void add_month(int n);
void add_year(int n);
int y;
Month m;
int d;
};
bool is_date(int y, Date::Month m, int d); // true for valid date
bool leapyear(int y); // true if y is a leap year
bool operator==(const Date& a, const Date& b);
bool operator!=(const Date& a, const Date& b);
Date operator++(Date a);
ostream& operator<<(ostream& os, const Date& d);
istream& operator>>(istream& is, Date& dd);
const Date& default_date();
}
// Chrono
add the code for add_month and
add_day. Write a mainwhich repeatedly reads a Date with
cin >>, uses add_month and add_day to add two months and two days to the
Date, and prints "Two months and two days later will be " followed by the
new value of the Date using cout <<.
*Hint*Though inefficient, a simple way
to implement add_day is to call your ++ the right number of times.
In add_month, check for landing on February 29th in a non-leap year (like
add_year does) and check for going past December (like your ++ does).