【C++】日付クラス+日付カレンダー+日付計算機
日付クラスでは、主に日付クラスの基本関数、構造、コピー構造、演算子の再ロード、解析を実現します.もちろん、ここで演算子のリロードは、=、<=、>=、など、実装する必要があります.
#include
using namespace std;
class Date
{
public:
Date(int year = 1990, int month = 1, int day = 1)
{
_year = year;
_month = month;
_day = day;
}
Date(const Date& d)
{
_year = d._year;
_month = d._month;
_day = d._day;
}
~Date()
{}
//
bool operator == (const Date& d)
{
return this->_year == d._year
&& this->_month == d._month
&& this->_day == d._day;
}
bool operator d);
}
bool operator >(const Date& d)
{
if (_year>d._year)
{
return true;
}
else
{
if (_year == d._year)
{
if (_month > d._month)
{
return true;
}
else
{
if (_month == d._month)
{
if (_day > d._day)
{
return true;
}
}
}
}
}
return false;
}
bool operator >=(const Date& d)
{
return !(*this
, , , , , , 12 1, 。 , 2 , ? , , 2 1 。 , , 。
//
Date operator+ (int day);
Date operator+= (int day);
Date operator- (int day)
{
this->_day -= day;
while (_day 0)//
{
this->_day += day;
while (_day > GetMonthDay(2016, 2))
{
_day -= GetMonthDay(2016, 2);
_month += 1;
if (_month > 12)
{
_month = 1;
_year += 1;
}
}
}
else//
{
this->_day -= day;
while (_day