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

C++ FOLLOW DIRECTIONS TO MODIFY THE CODE GIVEN, Define your getter or accessor m

ID: 656708 • Letter: C

Question

C++ FOLLOW DIRECTIONS TO MODIFY THE CODE GIVEN,

Define your getter or accessor methods by returning appropriate data member specified. You have 3 getter methods above; getMonth(), getDay() and getYear(). For your getMonth() method/function, you will need to return the month value, and so on.

Also, Define your setter or mutator methods by setting appropriate data member specified. For example, in setMonth() method/function, you will need to set the month value using the name in the parameter, and so on.

#include
#include
#include "Date.h"

using std::cout;
using std::endl;
using std::cin;

int main()
{

Date mdyDate( );

//display initial date
mdyDate.displayDate();

return 0;
}
----------------------------------------------------------------------------------------------------------------------------------

// Date.h file

#include
#include
#include

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();   // display function

};

-------------------------------------------------------------------------------------------------------------------------------

class definition

// Date.cpp file

#include

using std::cout;
using std::endl;

#include "Date.h"

//initialization with constructor
Date::Date()
{


setMonth(1);
setDay(1);
setYear(2011);

}

// set day function
void Date::setDay(int d)
{
day = d;
}

// set month function
void Date::setMonth(int m)
{
month = m;
}

// set year function
void Date::setYear(int y)
{
year = y;
}

// get day function
int Date::getDay()
{
return day;
}

// get month function
int Date::getMonth()
{
return month;
}

// get year function
int Date::getYear()
{
return year;
}


// display date function
void Date::displayDate()
{
cout << getMonth() << "/" << getDay() << "/" << getYear() << endl;
}

Explanation / Answer

#include <iostream>
#include <Date.h>
using std::cout;
using std::endl;
using std::cin;
int main()
{
Date mdyDate( );
mdyDate.displayDate();
return 0;
}
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();   
};
class definition
using std::cout;
using std::endl;
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;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote