Question: Programming language is C++. Show finished code and an example of the output on PuTTY when done. Use g++ -std=c++17 to compile the code with

Programming language is C++. Show finished code and an example of the output on PuTTY when done. Use g++ -std=c++17 to compile the code with the chrono.cpp and chrono.h file on PuTTY.

Programming language is C++. Show finished code and an example of the

output on PuTTY when done. Use g++ -std=c++17 to compile the code

//chrono.h

//file chrono.h

#include "std_lib_facilities_4.h"

namespace Chrono { enum class Month { jan = 1, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec };

class Date { public: 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

/onmodifying operations: int day() const { return d; } Month month() const { return m; } int year() const { return y; }

Date &operator++(); //modifying operations: void add_day(int n); void add_month(int n); void add_year(int n);

private: int y; Month m; int d;

};

bool is_date(int y, 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);

ostream& operator

istream& operator>>(istream& is, Date& dd);

} //Chrono

//chrono.cpp

#include "Chrono.h"

namespace Chrono { //member function defintions:

Date::Date(int yy, Month mm, int dd) :y{ yy }, m{ mm }, d{ dd } { if (!is_date(yy, mm, dd)) throw Invalid{};

}

const Date& default_date() { static Date dd{ 2001,Month::jan,1 }; //start of 21st century return dd; }

Date::Date() :y{ default_date().year() }, m{ default_date().month() }, d{ default_date().day() } { }

Date& Date::operator++() { d = d + 1; if (is_date == false) { d = 1; } d = 1; if (m == Month::dec) { m == Month::jan; y = y + 1; }

else { int oldM = (int)m; oldM = oldM + 1; m = static_cast(oldM); }

return *this; }

void Date::add_day(int n) { // }

void Date::add_month(int n) { // }

void Date::add_year(int n) { if (m == Month::feb&&d == 29 && !leapyear(y + n)) { //beware of leap years! m = Month::mar; //use March 1 instead of February 29 d = 1; } y += n; } //helper functions:

bool is_date(int y, Month m, int d) { //assume that y is valid

if (d

int days_in_month = 31; //most months have 31 days

switch (m) { case Month::feb: //the length of February varies days_in_month = (leapyear(y)) ? 29 : 28; break; case Month::apr:case Month::jun: case Month::sep:case Month::nov: days_in_month = 30; //the rest have 30 days break; }

if (days_in_month

return true; } bool leapyear(int y) { //see exercise 10 } bool operator==(const Date& a, const Date& b) { return a.year() == b.year() && a.month() == b.month() && a.day() == b.day(); }

bool operator!=(const Date& a, const Date& b) { return !(a == b); } ostream& operator

istream& operator >> (istream& is, Date& dd) { int y, m, d; char ch1, ch2, ch3, ch4; is >> ch1 >> y >> ch2 >> m >> ch3 >> d >> ch4; if (!is) return is; if (ch1 != '(' || ch2 != ',' || ch3 != ',' || ch4 != ')') { is.clear(ios_base::failbit); return is; }

dd = Date(y, Month(m), d);

return is; }

enum class Day { sunday, monday, tuesday, wednesday, thursday, friday, saturday };

Day day_of_week(const Date& d) { return Day::sunday; } Day next_Sunday(const Date& d) { return Day:: sunday; } Day next_weekday(const Date& d) { return Day::sunday; }

} //Chrono

3. (20 points) Start with Chrono,h and Chrono.cpp in section 9.8; for now put a dummy "return Sunday; or "return d in the last 3 functions on pages 337-338. Add a prefix operator to the Date class by putting the declaration in the Date class in Chrono,h and the definition in Chrono.cpp. The prefix operator should change a date to "tomorrow" using the following pseudocode: Date& operator ++0{ /addlto d //tomorrow, unless we were at the end ofthe month //if is date is false /eed to change to first of next month set d to 1 if m is December Ineed to change to next year too set m to January increment y else increment m return this

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!