int
getmonthday
(int year,
int month)
;int day = days[month];if
(month ==2&&
((year %4==
0)&&(year %
100!=0)
|| year %
400==0)
)return day;
}
date
(int year =
1900
,int month =1,
int day =1)
else
}
date
(const date& d)
~
date()
// d2 = d3 -> d2.operator=(&d2, d3)
date&
operator=(
const date& d)
return
*this
;}
date&
operator+=
(int day)
_day +
= day;
while
(_day >
getmonthday
(_year, _month))}
return
*this
;}
date operator+(
int day)
date operator-(
int day)
date&
operator-=
(int day)
_day -
= day;
while
(_day <=0)
_day +
=getmonthday
(_year, _month);}
return
*this
;}
date&
operator++(
)
date operator++(
int)
date operator--(
int)
前置–
date&
operator--(
)
// >運算子過載
bool
operator
>
(const date& d)
}return
false;}
// ==運算子過載
bool
operator==(
const date& d)
// >=運算子過載
inline
bool
operator
>=
(const date& d)
// 《運算子過載
bool
operator
<
(const date& d)
// <=運算子過載
bool
operator
<=
(const date& d)
// !=運算子過載
bool
operator!=(
const date& d)
// 日期-日期 返回天數
日期類的實現(C )
date.h define crt secure no warning 1 pragma once include include using namespace std class date date const date d year d.year month d.month day d.day...
C 日期類的實現
實現日期類,就是實現其中的幾個預設的成員函式以及一些運算子的過載的實現。使用初始化成員列表初始化年月日,並且對日期的非法性做以判斷。date date int year,int month,int day year year month month day day 這裡對日期的非法性判斷,主要 如下...
C 日期類的實現
include include include using namespace std class date 獲取每個月的天數 int getmonthday int year,int month if month 2 isleap year return days month 判斷日期是否合法 b...