-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy path12.6 Equality_Inequality_Comparison.cpp
More file actions
52 lines (42 loc) · 1.13 KB
/
12.6 Equality_Inequality_Comparison.cpp
File metadata and controls
52 lines (42 loc) · 1.13 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
#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) const
{
return ((day == compareTo.day)
&& (month == compareTo.month)
&& (year == compareTo.year));
}
bool operator!= (const Date& compareTo) const
{
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 << "Equality operator: The two are on the same day" << endl;
else
cout << "Equality operator: The two are on different days" << endl;
if (holiday1 != holiday2)
cout << "Inequality operator: The two are on different days" << endl;
else
cout << "Inequality operator: The two are on the same day" << endl;
return 0;
}