-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDate.h
More file actions
56 lines (48 loc) · 1.81 KB
/
Date.h
File metadata and controls
56 lines (48 loc) · 1.81 KB
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
#pragma once
#include <iostream>
using namespace std;
class Date
{
private:
int year, month, day;
public:
//Date() {}
Date(int year=2018, int month=2, int day=22);
Date(const Date &d) :year(d.year), month(d.month), day(d.day) {}
~Date() {}
//得到年月日
int getYear()const { return year; }
int getMonth()const { return month; }
int getDay()const { return day; }
void setDate(int year, int month, int day); //设置日期
bool isLeapYear(int year)const; //判断是否为闰年
int daysOfMonth(int year, int month)const; //得到某个月的天数
void show()const; //显示日期
Date changeDays(const int days)const; //改变日期
int distance(const Date &d)const; //计算两个日期之间的天数
/*重载运算符*/
//日期加上days个天数
friend Date operator +(const Date &d, const int days);
friend Date operator +(const int days, const Date &d);
Date& operator +=(int days);
//日期自增一天
Date& operator ++();
Date operator ++(int);
//日期减去days个天数
friend Date operator -(const Date &d, const int days);
friend int operator -(const Date &d1, const Date &d2);
Date& operator -=(int days);
//日期自减一天
Date& operator --();
Date operator --(int);
//日期大小比较
friend bool operator >(const Date &d1, const Date &d2);
friend bool operator >=(const Date &d1, const Date &d2);
friend bool operator <(const Date &d1, const Date &d2);
friend bool operator <=(const Date &d1, const Date &d2);
friend bool operator ==(const Date &d1, const Date &d2);
friend bool operator !=(const Date &d1, const Date &d2);
//输出,输入日期
friend ostream& operator <<(ostream &out, const Date &d);
friend istream& operator >> (istream &in, Date &d);
};