-
Notifications
You must be signed in to change notification settings - Fork 23
/
12.7 ComparisonLessThanGreaterThanEqualTo.cpp
83 lines (68 loc) · 1.83 KB
/
12.7 ComparisonLessThanGreaterThanEqualTo.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
using namespace std;
class Date
{
private:
int day, month, year;
public:
Date(int inMonth, int inDay, int inYear)
: month(inMonth), day(inDay), year(inYear) {}
bool operator< (const Date& compareTo)
{
if (year < compareTo.year)
return true;
else if ((year == compareTo.year) && (month < compareTo.month))
return true;
else if ((year == compareTo.year) && (month == compareTo.month)
&& (day < compareTo.day))
return true;
else
return false;
}
bool operator<= (const Date& compareTo)
{
if (this->operator== (compareTo))
return true;
else
return this->operator< (compareTo);
}
bool operator > (const Date& compareTo)
{
return !(this->operator<= (compareTo));
}
bool operator== (const Date& compareTo)
{
return ((day == compareTo.day)
&& (month == compareTo.month)
&& (year == compareTo.year));
}
bool operator>= (const Date& compareTo)
{
if(this->operator== (compareTo))
return true;
else
return this->operator> (compareTo);
}
void DisplayDate()
{
cout << month << " / " << day << " / " << year << endl;
}
};
int main()
{
Date holiday1 (12, 25, 2021);
Date holiday2 (12, 31, 2021);
cout << "holiday 1 is: ";
holiday1.DisplayDate();
cout << "holiday 2 is: ";
holiday2.DisplayDate();
if (holiday1 < holiday2)
cout << "operator<: holiday1 happens first" << endl;
if (holiday2 > holiday1)
cout << "operator>: holiday2 happens later" << endl;
if (holiday1 <= holiday2)
cout << "operator<=: holiday1 happens on or before holiday2" << endl;
if (holiday2 >= holiday1)
cout << "operator>=: holiday2 happens on or after holiday1" << endl;
return 0;
}