-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8.cpp
41 lines (37 loc) · 746 Bytes
/
8.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
// Binary operator overloading
#include <iostream>
class Distance{
private:
int feet;
float inches;
public:
Distance() : feet(0) ,inches(0.0){}
Distance(int ft, float in) : feet(ft) , inches(in){
}
void getdist(){
std::cout <<"\nEnter the feet";
std::cin >> feet;
std::cout << "\nEnter the inches";
std::cin >> inches;
}
void showdist(){
std::cout << feet << "/ " << inches <<"/";
}
void operator+=(Distance &d2);
};
void Distance::operator+=(Distance &d2){
feet+=d2.feet;
inches+= d2.inches;
if(inches>=12.0){
inches-=12;
feet++;
}
}
int main(){
Distance d1;
d1.getdist();
Distance d2;
d2.getdist();
d1+= d2;
d1.showdist();
}