-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathq12.cpp
54 lines (42 loc) · 1.28 KB
/
q12.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
// WAP to overload >, <, == operator to compare two amount using the concept of overloading.
#include <iostream>
using namespace std;
class Amount {
private:
int rupees;
int paise;
public:
Amount() : rupees(0), paise(0) {}
Amount(int r, int p) : rupees(r), paise(p) {}
friend bool operator>(const Amount &a1, const Amount &a2);
friend bool operator<(const Amount &a1, const Amount &a2);
friend bool operator==(const Amount &a1, const Amount &a2);
void display() {
cout << "Rupees: " << rupees << " Paise: " << paise << endl;
}
};
bool operator>(const Amount &a1, const Amount &a2) {
int p1 = a1.rupees * 100 + a1.paise;
int p2 = a2.rupees * 100 + a2.paise;
return p1 > p2;
}
bool operator<(const Amount &a1, const Amount &a2) {
int p1 = a1.rupees * 100 + a1.paise;
int p2 = a2.rupees * 100 + a2.paise;
return p1 < p2;
}
bool operator==(const Amount &a1, const Amount &a2) {
return (a1.rupees == a2.rupees && a1.paise == a2.paise);
}
int main() {
Amount a1(100, 50);
Amount a2(50, 100);
if (a1 > a2) {
cout << "a1 is greater than a2" << endl;
} else if (a1 < a2) {
cout << "a1 is less than a2" << endl;
} else if (a1 == a2) {
cout << "a1 is equal to a2" << endl;
}
return 0;
}