Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Could you please update the code below for the Date.cpp to output dates in this

ID: 3713210 • Letter: C

Question

Could you please update the code below for the Date.cpp to output dates in this format: MM/DD/YYYY and not DD/MM/YYYY. Please, pay a closer attention to the output in the question below.

#include "stdafx.h"

#include <iostream>

#include <iomanip>

#include <string>

#include "Date.h"

using namespace std;

Date::Date()

{

month = 1;

day = 1;

year = 1970;

}

Date::Date(int m, int d, int y)

{

month = m;

day = d;

year = y;

}

void Date::setDate(int mm, int dd, int yyyy)

{

month = mm;

day = dd;

year = yyyy;

}

void Date::displayDate() const

{

cout << day << "/";

if (month<10)

cout << setw(2) << setfill('0') << right;

cout << month << "/";

cout << setw(4) << year;

}

bool Date::operator==(const Date& other) const

{

if (day == other.day && month == other.month && year == other.year)

return true;

else

return false;

}

bool Date::operator!=(const Date& other) const

{

if (day == other.day && month == other.month && year == other.year)

return false;

else

return true;

}

bool Date::operator<(const Date& other) const

{

if (year<other.year)

return true;

else if (year>other.year)

return false;

else

{

if (month<other.month)

return true;

else if (month>other.month)

return false;

else

{

if (day<other.day)

return true;

else

return false;

}

}

}

bool Date::operator>(const Date& other) const

{

if (year>other.year)

return true;

else if (year<other.year)

return false;

else

{

if (month>other.month)

return true;

else if (month<other.month)

return false;

else

{

if (day>other.day)

return true;

else

return false;

}

}

}

bool Date::operator<=(const Date& other) const

{

if (year<other.year)

return true;

else if (year>other.year)

return false;

else

{

if (month<other.month)

return true;

else if (month>other.month)

return false;

else

{

if (day <= other.day)

return true;

else

return false;

}

}

}

void Date::setDefaultDate()

{

month = 1;

day = 1;

year = 1970;

}

bool Date::operator>=(const Date& other) const

{

if (year>other.year)

return true;

else if (year<other.year)

return false;

else

{

if (month>other.month)

return true;

else if (month<other.month)

return false;

else

{

if (day >= other.day)

return true;

else

return false;

}

}

}

ostream &operator<<(ostream &output, const Date &d)

{

output << d.day << "/";

if (d.month<10)

output << setw(2) << setfill('0') << right;

output << d.month << "/";

output << setw(4) << d.year << " ";

return output;

}

istream &operator>>(istream &input, Date &d)

{

int mm, dd, yyyy;

input >> mm >> dd >> yyyy;

d.setDate(mm, dd, yyyy);

return input;

}

Overloadedoperators-DateDriver #include "stdafx.h" #include

Explanation / Answer

You need to modify the overloaded function extraction operator ostream &operator<<

.

The corrected code is given below.

  ostream &operator<<(ostream &output, const Date &d)  {        if (d.month<10)      output << setw(2) << setfill('0') << right;      output << d.month << "/";      output << d.day << "/";      output << setw(4) << d.year << " ";      return output;  }