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

// Date.h class Date{ private: int day; int month; int year; public: Date(); int

ID: 657410 • Letter: #

Question

// Date.h

class Date{
private:
   int day;
   int month;
   int year;
public:
   Date();
   int getDay();
   void setDay(int);
   int getMonth();
   void setMonth(int);
   int getYear();
   void setYear(int);
   void displayDate();

   //Added new functions here
   void printDateUS();
   void printDateENG();
};

// Date.cpp

#include <iostream>
#include "Date.h"
using namespace std;

Date::Date(){
   setMonth(1);
   setDay(1);
   setYear(2011);
}
void Date::setDay(int d){
   day = d;
}
void Date::setMonth(int m){
   month = m;
}
void Date::setYear(int y){
   year = y;
}
int Date::getDay(){
   return day;
}
int Date::getMonth(){
   return month;
}
int Date::getYear(){
   return year;
}
void Date::displayDate(){
   cout << getMonth() << "/" << getDay() << "/" << getYear() << endl;
}

//Modified or added methods here

void Date::printDateUS()
{
   cout<<" US date : "<<endl; //Printing message
   cout<<month<<"/"<<day<<"/"<<year; //Printing each member of date in mm/dd/yyyy
}

void Date::printDateENG()
{
   cout<<" ENG date : "<<endl;//Printing message
   cout<<day<<"/"<<month<<"/"<<year; //Printing each member of date in dd/mm/yyyy
}

int main(){
   Date d1;
   cout << d1.getMonth() << "/" << d1.getDay() << "/" << d1.getYear() << endl;
   Date d2;
   int month, day, year;
   cout << "Enter the month: ";
   cin >> month;
   cout << "Enter the day: ";
   cin >> day;
   cout << "Enter the year: ";
   cin >> year;
   d2.setMonth(month);
   d2.setDay(day);
   d2.setYear(year);
   cout << d2.getMonth() << "/" << d2.getDay() << "/" << d2.getYear() << endl;

   //modified or added main() function code here
   d1.printDateUS(); //Calling date d1 with US format
   d2.printDateENG(); //Calling date d2 with ENG format
}

C++ Follow Directions down below to modify code up above:

Add a method/function called setDate() to the Date class. This method will accepts three integers, and they (the parameters) are for the month, day, year in that order.

So, your Date class now will be like this:

class Date

{

    private:

     int month;

     int day;

     int year;

    public:

     Date();

     int getMonth();

     int getDay();

     int getYear();

     void setMonth(int);

     void setDay(int);

     void setYear(int);

     void printDateUS();

     void printDateENG();

     void setDate(int,int,int);

};

Define method setDate() as explained above.

Now modify code for setting values for day, month, year with 3 separate calls to be replaced with one call.

Test program to ensure it is working correctly.

Explanation / Answer

Hello here is the solution:

// Date.h

class Date{
private:
   int day;
   int month;
   int year;
public:
   Date();
   int getDay();
   void setDay(int);
   int getMonth();
   void setMonth(int);
   int getYear();
   void setYear(int);
   void displayDate();

   //Added new functions here
   void printDateUS();
   void printDateENG();

   void setDate(int, int, int);
};

// Date.cpp

#include <iostream>
#include "Date.h"
using namespace std;

Date::Date(){
   setMonth(1);
   setDay(1);
   setYear(2011);
}
void Date::setDay(int d){
   day = d;
}
void Date::setMonth(int m){
   month = m;
}
void Date::setYear(int y){
   year = y;
}
int Date::getDay(){
   return day;
}
int Date::getMonth(){
   return month;
}
int Date::getYear(){
   return year;
}
void Date::displayDate(){
   cout << getMonth() << "/" << getDay() << "/" << getYear() << endl;
}

//Modified or added methods here

void Date::setDate(int m, int d, int y){
   day = d;
   month = m;
   year = y;
}

void Date::printDateUS()
{
   cout << " US date : " << endl; //Printing message
   cout << month << "/" << day << "/" << year; //Printing each member of date in mm/dd/yyyy
}

void Date::printDateENG()
{
   cout << " ENG date : " << endl;//Printing message
   cout << day << "/" << month << "/" << year; //Printing each member of date in dd/mm/yyyy
}

int main(){
   Date d1;
   cout << d1.getMonth() << "/" << d1.getDay() << "/" << d1.getYear() << endl;
   Date d2;
   int month, day, year;
   cout << "Enter the month: ";
   cin >> month;
   cout << "Enter the day: ";
   cin >> day;
   cout << "Enter the year: ";
   cin >> year;
  
   d2.setDate(month, day, year);
  
   //d2.setMonth(month);
   //d2.setDay(day);
   //d2.setYear(year);
  
   cout << d2.getMonth() << "/" << d2.getDay() << "/" << d2.getYear() << endl;

   //modified or added main() function code here
   d1.printDateUS(); //Calling date d1 with US format
   d2.printDateENG(); //Calling date d2 with ENG format
}