Question: C++ Given the date specification below, design, implement, and test the member functions and friend functions. Function showMMDDYY() outputs the date in the form 12/19/2015,

C++

Given the date specification below, design, implement, and test the member functions and friend functions. Function showMMDDYY() outputs the date in the form 12/19/2015, showMonth() in the form 19 December 2015, and showMon() in the form 19-Dec-2015. The op>() returns true if the this Date is later than the parameter Date, else false; similarly for the op<(). Docs op<<() calls showMon() you are free to choose a different format. The op-() returns the number of days between two dates if the this Date is earier than the parameter Date, the resultant value is negative. Note: op-() is likely the most difficult for you to implement, so do the others before attempting it; you can get full credit w/o op-() and 20 extra credit points with op-() successfully implemented. Partial main() and sample output are also given.

This is the class and int main() for this program i need the functions written for the class . i cant figure it out.

const int MONS = 12;

class Date

{

private:

int day; // day

int month; // month

int year; // year

static string names[MONS]; // array for names of months

static int numDays[MONS]; // array for number of days in each month

public:

Date(); // sets date to 1-Jan-2020

Date(int d, int m, int y); // validates parameters via calls to set_()'s

void setMonth(int m); // mutators

void setDay(int d);

void setYear(int y);

void showMMDDYY() const; // accessors

void showMonth() const;

void showMon() const;

bool isLeapYear(int y) const;

Date operator++(); // prefix ++

Date operator++(int); // postfix ++

Date operator--(); // prefix --

Date operator--(int); // postfix --

bool operator>(const Date &); // greater-than operator

int operator-(const Date &); // returns # of days between dates

bool operator<(const Date &); // less-than operator

friend ostream & operator<<(ostream & os, const Date & d); // overloaded <<

friend istream & operator>>(istream & us, Date & d); // overloaded >>

};

string Date::names[] = { "January", "February", "March", "April", "May",

"June", "July", "August", "September", "October", "November", "December" };

int Date::numDays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

int main()

{

Date d1(14, 3, 2008);

Date d2(31, 12, 2006);

Date d3; // invoke default ctor 1-Jan-2020

int days; // for # of days between 2 dates

cout << " Testing op<<() and op(): ";

cout << "Date from default ctor: ";

cout << d3 << endl;

cout << " The day before: ";

cout << --d3 << endl; // go to previous year

cout << " Testing op-(): "; // subtraction operator

// make the subtraction operator your last priority

// days = d1 - d2; // demo overloaded - and << operators

// cout << d1 << " - " << d2 << " = " << days << " days ";

// Date d5(14, 3, 2007);

// Date d4(31, 12, 2005);

// days = d5 - d4; // demo overloaded - and << operators

// cout << d5 << " - " << d4 << " = " << days << " days ";

// days = d4 - d1; // demo overloaded - and << operators

// cout << d4 << " - " << d1 << " = " << days << " days ";

cout << " Testing op++() and op--() - pre- and postfix: ";

cout << ++d1 << endl; // demo overloaded ++ operators

cout << d1++ << endl;

cout << d1 << endl;

d1.setDay(31);

d1.setMonth(12);

cout << ++d1 << endl;

d1.setDay(10); // demo overloaded -- operators

// similar to the ++ ops above

cout << " Testing op>>(): ";

cin >> d1; // demo overloaded >> operator

cout << "You entered " << d1 << endl;

d1.showMonth();

cout << endl;

d1.showMMDDYY();

cout << endl;

cout << " Testing op>() and op<(): ";

// supply a couple of if..else statements here

return 0;

}

This is the output of the program

Testing op<<() and op--():

Date from default ctor: 1-Jan-2020

The day before: 31-Dec-2019

Testing op-():

14-Mar-2008 - 31-Dec-2006 = 439 days

14-Mar-2007 - 31-Dec-2005 = 438 days

31-Dec-2005 - 14-Mar-2008 = -804 days

Testing op++() and op--() - pre- and postfix:

15-Mar-2008

15-Mar-2008

16-Mar-2008

1-Jan-2009

9-Jul-2003

9-Jul-2003

8-Jul-2003

Testing op>>():

Enter day: 11

Enter month: 12

Enter year: 2015

You entered 11-Dec-2015

11 December 2015

12/11/2015

Testing op>() and op<():

11-Dec-2015 is later than 31-Dec-2006

14-Mar-2007 is earlier than 11-Dec-2015 */

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!