Hello everyone,
I have a hw assignment where I have to take a program I've already done, and overload the increment decrement operators.
Now My teacher gave me a cheat sheet in terms of overloading, but I have no idea how I'm supposed to take that sheet sheet and apply it to this program.
Here is my class atm:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#ifndef dateType_H
#define dateType_H
class dateType
{
public:
void setDate(int month, int day, int year);
int getDay() const;
int getMonth() const;
int getYear() const;
void printDate() const;
bool isLeapYear(int year);
dateType(int month = 1, int day = 1, int year = 1900);
private:
int dMonth; //variable to store the month
int dDay; //variable to store the day
int dYear; //variable to store the year
int monthMax; //variable to store the max days in the entered month
};
#endif
|
And heres my implementation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
void dateType::setDate(int month, int day, int year)
{
int maxDays = 0;
if (year > 1699 && year < 4000)
{
dYear = year;
}
else
dYear = 2014;
if (month > 0 && month < 13)
{
dMonth = month;
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
maxDays = 31;
break;
case 4:
case 6:
case 9:
case 11:
maxDays = 30;
break;
case 2:
{
if (isLeapYear(year) == true)
maxDays = 29;
else
maxDays = 28;
break;
}
default:
dDay = 31;
}
}
if (day < 1 || day > maxDays)
dDay = 1;
else
dDay = day;
cout << "There are a maximum of " << maxDays << " This month" << endl;
monthMax = maxDays;
}
int dateType::getDay() const
{
return dDay;
}
int dateType::getMonth() const
{
return dMonth;
}
int dateType::getYear() const
{
return dYear;
}
bool dateType::isLeapYear(int year)
{
if (year % 4 != 0) {
return false;
}
else if (year % 400 == 0) {
return true;
}
else if (year % 100 == 0) {
return false;
}
else {
return true;
}
}
void dateType::printDate() const
{
cout << "The date you entered is:" << endl;
cout << dMonth << "/" << dDay << "/" << dYear << endl;
}
dateType::dateType(int month, int day, int year)
{
}
|
I know this applies somewhere:
className operator++();
className className::operator++()
{
this.memberVariable++;
return *this;
}
But I have no idea where I'm supposed to put everything.
I did experiment with putting
in my class, but when I put
1 2 3 4 5
|
dateType dateType::operator++()
{
this.dDay++;
return *this;
}
|
in my implementation it started throwing all kinds of errors. I'm so very lost with this.
Anyone out there know what I'm doing wrong?