I have a class called Date that accepts three integers: day, month, and year, which are validated (no months with more than 31 days, Feb can have 29 days on a leap year, etc) and I have to add on to it to make it so it can increment and decrement the a given date, and also subtract one date from another using several overloaded operators.
Right now I'm working to overload my ++ prefix operator and making a Date class object called simplify that will make sure the dates increment to the correct month (make sure Jan 31, 2012 becomes Feb 1,2012 when incremented, and not Jan 32), but I'm having a couple problems. First, I keep getting errors when trying to overload my operator
Date.h
Date& operator ++ ();
Date.cpp
1 2 3 4 5 6 7
|
Date Date::operator - ()
{
++day;
simplify();
return *this;
}
|
I keep getting errors telling me day and simplify are undefined. Can anyone tell me what I'm doing wrong?
Also, I'm having trouble with my simplify object. I've been working to make it handle every date exception, but I'm not sure about it because I'm working with "abs" and I've been told "abs" would be useful in this situation, but I'm not really familiar with it, and I'm not sure exactly what it does.
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
|
void Date::simplify()
{
//Incrementors
if (month = 4 || 6 || 9 || 11 && day > 30)
{
month += (day / 30);
day = (day % 30);
}
else if ( month = 1 || 3 || 5 || 7 || 8 || 10 && day > 31)
{
month += (day / 31);
day = day % 31;
}
else if ( month = 2 && day > 28 && year % 400 =! 0)
{
month += (day / 28);
day = day % 28;
}
else if (month = 2 && day > 29 && year % 400 = 0)
{
month += (day / 29);
day = day % 29;
}
else if (month = 12 && day > 31)
{
month = (day / 31);
day = day % 31;
year = year + 1;
}
//Decrementors
else if (month = 4 || 6 || 9 || 11 && day < 1)
{
month -= ((abs(day) / 30) + 1);
day = day - (abs(day) % 30);
}
else if (month = 3 || 5 || 7 || 8 || 10 || 12 && day < 1)
{
month -= ((abs(day) / 31) +1);
day = 31 - (abs(day) % 31);
}
else if (month = 2 && day < 1 && year % 400 != 0)
{
month -= ((abs(day) / 28) +1);
day = 28 - (abs(day) % 28);
}
else if (month = 2 && day < 1 && year % 400 = 0)
{
month -= ((abs(day) / 29 ) +1);
day = 29 - (abs(day) % 29);
}
else if (month = 1 && day < 1)
{
month -= ((abs(day) / 31) + 1);
day = 31 - (abs(day) % 31);
year = year - 1;
}
}
|
I know this is a bear of a post, but if someone could give me a little advice and point me in the right direction, I would greatly appreciate it. Thanks a lot.