Skip to content

Commit 1343c5f

Browse files
authored
Create Binary_Operator_Overloading.cpp
1 parent 23daa8c commit 1343c5f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

cpp/Binary_Operator_Overloading.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <iostream>
2+
using namespace std;
3+
class Distance {
4+
public:
5+
int feet, inch;
6+
Distance() {
7+
feet = 0;
8+
inch = 0;
9+
}
10+
Distance(int f, int i){
11+
feet = f;
12+
inch = i;
13+
}
14+
Distance operator+(Distance d2) {
15+
Distance d3;
16+
d3.feet = feet + d2.feet;
17+
d3.inch = inch + d2.inch;
18+
return d3;
19+
}
20+
};
21+
int main() {
22+
Distance d1(8, 9);
23+
Distance d2(10, 2);
24+
Distance d3;
25+
d3 = d1 + d2;
26+
cout << "\nTotal Feet & Inches: " << d3.feet << "'" << d3.inch;
27+
return 0;
28+
}

0 commit comments

Comments
 (0)