-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo17.cpp
59 lines (50 loc) · 1.05 KB
/
demo17.cpp
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
#include <iostream>
using namespace std;
class Date
{
public:
Date(int m=0, int d=0, int y=0):month(m),day(d),year(y) {}
int operator == (Date& dt) const;
int operator != (Date& dt) const;
int operator < (Date& dt) const;
int operator > (Date& dt) const;
int operator <= (Date& dt) const;
int operator >= (Date& dt) const;
private:
int month, day, year;
};
int Date::operator == (Date& dt) const
{
return (this->month == dt.month) && (this->day == dt.day) && (this->year == dt.year);
}
int Date::operator != (Date& dt) const
{
return !(*this == dt);
}
int Date::operator < (Date& dt) const
{
if(this->year == dt.year)
{
if(this->month == dt.month)
{
if(this->day == dt.day)
return 0;
else
return this->day < dt.day;
}
else
return this->month < dt.month;
}
else
return this->year < dt.year;
}
int main()
{
Date d1(2, 14, 2008);
Date d2(3, 14, 2008);
Date d3(2, 14, 2008);
cout << "d1 == d2 : " << (d1 == d2) << endl;
cout << "d1 == d3 : " << (d1 == d3) << endl;
cout << "d1 != d2 : " << (d1 != d2) << endl;
return 0;
}