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

Create a \"Date\" class that contains: three private data members: month day yea

ID: 3650831 • Letter: C

Question

Create a "Date" class that contains:

three private data members:
month
day
year
(I leave it to you to decide the type)

"setters" and "getters" for each of the data (6 functions in total)
The idea of the "setter" would be to provide error checking. For simplicity, you do not have to provide any

one default constructor (no arguments)

one constructor with three arguments: month, day, and year

a printDate function. This function will have no arguments and no return type

a sameMonth function. This function will have one Date argument and a boolean return type

Explanation / Answer

please rate - thanks

#include <iostream>
#include <string>
using namespace std;
class Date
{
private: int month,day,year;
public:
Date::Date(int m, int d, int y)
{month=m;
day=d;
year=y;
}
Date::Date()
{month=1;
day=1;
year=2000;
}

double Date::getMonth()
{return month;
}
void Date::setMonth(int m)
{month=m;
}

double Date::getDay()
{return day;
}
void Date::setDay(int m)
{day=m;
}
double Date::getYear()
{return year;
}
void Date::setYear(int m)
{year=m;
}
bool Date::sameMonth(Date o)
{if(month==o.month)
     return true;
else
     return false;
}
void Date::print()
{
cout<<"The Date is "<<month<<"/"<<day<<"/"<<year<<endl;
}
};
int main()
{
Date d1 ;
Date d2(10,2,2012);
Date d3(1,5,1900);
cout<<"initially Date d1 : ";
d1.print();
d1.setMonth(10);
cout<<"after changing year d1 : ";
d1.print();
cout<<"Date d2 : ";
d2.print();
cout<<"Date d3 : ";
d3.print();
if(d1.sameMonth(d2))
     cout<<"d1 and d2 have the same month ";
else
      cout<<"d1 and d2 do not have the same month ";
if(d3.sameMonth(d2))
     cout<<"d3 and d2 have the same month ";
else
      cout<<"d3 and d2 do not have the same month ";
if(d1.sameMonth(d3))
     cout<<"d1 and d3 have the same month ";
else
      cout<<"d1 and d3 do not have the same month ";          
system("pause");
return 0;
}