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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
int Date::lastdayofmonth()
{
switch(month)
{
case January: return 31; break; case February: if (leapYear(year)) return 29; else return 28; break; case March: return 31; break; case April: return 30; break;
case May: return 31; break; case June: return 30; break; case July: return 31; break; case August: return 31; break; case September: return 30; break; case October: return 31; break;
case November: return 30; break; case December: return 31; break; default: return 0; break;
}
}
void Date::addmonth()
{
++month;
}
void Date::addyear()
{
++year;
}
// overloaded output operator
ostream &operator<<( ostream &output, const Date &d )
{
char msg[] = "", msg1[] = "January", msg2[] = "February", msg3[] = "March", msg4[] = "April", msg5[] = "May", msg6[] = "June",
msg7[] = "July", msg8[] = "August", msg9[] = "September", msg10[] = "October", msg11[] = "November", msg12[] = "December";
//static char *monthName[13] = {msg, msg1, msg2, msg3, msg4, msg5, msg6, msg7, msg8, msg9, msg10, msg11, msg12};
string monthName[13] = {msg, msg1, msg2, msg3, msg4, msg5, msg6, msg7, msg8, msg9, msg10, msg11, msg12};
output << monthName[ d.month ] << ' ' << d.day << ", " << d.year;
return output; // enables cascading
} // end function operator<<
const bool Date::operator == (const Date & rhs)
{
if (month == rhs.month && day == rhs.day && year == rhs.year)
return true;
else return false;
}
const bool Date::operator !=(const Date & rhs)
{
if ((*this == rhs))
return false;
else return true;
}
const bool Date::operator < (const Date & rhs)
{
if (year >= rhs.year)
return false;
if (month >= rhs.month)
return false;
if (day < rhs.day)
return true;
}
const bool Date::operator > (const Date & rhs)
{
if (year > rhs.year)
return true;
if (year < rhs.year)
return false;
if (month > rhs.month)
return true;
if (month < rhs.month)
return false;
if (day > rhs.day)
return true;
else return false;
}
const bool Date::operator <= (const Date & rhs)
{
if (year >= rhs.year)
return false;
if (month >= rhs.month)
return false;
if (day <= rhs.day)
return true;
}
const bool Date::operator >= (const Date & rhs)
{
if (year <= rhs.year)
return false;
if (month <= rhs.month)
return false;
if (day >= rhs.day)
return true;
}
int Date::getdate(int & m, int & d, int & y)
{
char dateStr [9];
_strdate( dateStr); char tempdate[7] = {dateStr[0], dateStr[1], dateStr[3], dateStr[4], dateStr[6], dateStr[7] };
int DD[6]; int D = atoi(tempdate);
for (int i = 0; i < 6; ++i)
DD[i] = int(tempdate[i]) - 48;
year = 10 * DD[4] + DD[5];
month = 10 * DD[0] + DD[1];
day = 10 * DD[2] + DD[3];
year += 2000;
m = month; d = day; y = year;
return D;
}
int Date::getday()
{
return day;
}
int Date::getmonth()
{
return month;
}
int Date::getyear()
{
return year;
}
#endif
|