Question: C++!!! Develop an implementation file (call it DateImp.cpp ) for the modified Date.h . Your solution should have the following overloaded operators: ++ Prefix and

C++!!!

Develop an implementation file (call it DateImp.cpp) for the modified Date.h. Your solution should have the following overloaded operators:

++ Prefix and postfix increment operators. These operators should increment the objects day member.

-- Prefix and postfix decrement operators. These operators should decrement the objects day member.

- Subtraction operator. If one Date object is subtracted from another, the operator should give the number of days between the two dates. For example, if April 10, 2014 is subtracted from April 18, 2014, the result will be 8.

<< coutss stream insertion operator. This operator should cause the date to be displayed in the form: April 18. 2014

>> cins stream extraction operator. This operator should prompt the user for a date to be stored in a Date object.

The class should detect the following SPECIAL conditions and handle them accordingly:

When a date is set to the last day of the month and incremented, it should become the first day of the following month.

When a date is set to December 31 and incremented, it should become January 1 of the following year.

When a date is set to the first day of the month and decremented, it should become the last day of the previous month.

When a date is set to January 1 and decremented, it should become December 31 of the previous year.

Input validation: The overloaded >> operator should not accept invalid dates. For example:

The date 13/45/2014 should not be accepted.

Valid year range: 1900<=year<=9999

Dont forget to validate the 12 months of the year

Dont forget to validate the days of each month

GENERAL RESTRICTIONS

No global variables

No labels or go-to statements

No infinite loops, examples include:

for(;;)

while(1)

while(true)

do{//code}while(1);

No break statements to exit loops

main.cpp

#include

#include

using namespace std;

#include "Date.h"

//*************************************

// Function main *

//*************************************

int main()

{

// Demonstrate the overloaded - and << operators.

Date d1(2, 2, 2006);

Date d2(11, 10, 2003);

int days = d1 - d2;

cout << d1 << " minus " << d2 << " equals " << days << " days ";

// Demonstrate the overloaded ++ operators.

cout << ++d1 << endl;

cout << d1++ << endl;

cout << d1 << endl;

d1.setDay(31);

d1.setMonth(12);

cout << ++d1 << endl << endl;

// Demonstrate the overloaded -- operators.

d1.setDay(10);

d1.setMonth(7);

d1.setYear(2003);

cout << --d1 << endl;

cout << d1-- << endl;

cout << d1 << endl;

d1.setDay(1);

d1.setMonth(1);

d1.setYear(2004);

cout << --d1 << endl;

// Demonstrate the overloaded >> operator.

cin >> d1;

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

system("pause");

return 0;

}

Date.h

#ifndef DATE_H

#define DATE_H

#include

#include

using namespace std;

class Date;

// Constants

const int NUM_MONTHS = 12;

// Declaration of the Date class

class Date

{

public:

// Constructors

Date();

Date(int, int, int);

// Mutators

void setMonth(int m);

void setDay(int d);

void setYear(int y);

// Other member functions

void showDate1();

void showDate2();

void showDate3();

bool isLeapYear(int);

// Overloaded operators

Date operator ++(); // Prefix ++

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

Date operator --(); // Prefix --

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

int operator -(const Date &); // Subtraction operator

friend ostream &operator <<(ostream &, const Date &); // Overloaded << operator

friend istream &operator >>(istream &, Date &); // Overloaded >> operator

private:

int month; // To hold the month

int day; // To hold the day

int year; // To hold the year

// An array of strings to hold

// the names of the months

string names[NUM_MONTHS];

// An array to hold the number of days

// that each month has.

int numDays[NUM_MONTHS];

// Private member function to assign

// the month names to the names array

void setNames();

// Private member function to assign

// the numbers of days to the numDaus array

void setDays();

};

#endif

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!