-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses-return-obj.cpp
More file actions
56 lines (50 loc) · 1.08 KB
/
classes-return-obj.cpp
File metadata and controls
56 lines (50 loc) · 1.08 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
53
54
55
56
#include <iostream>
#include <conio.h>
using namespace std;
class Distance{
private:
int inch;
int feet;
public:
void setDistance(int f, int i){
feet = f;
inch = i;
}
Distance add(Distance d1)
{
Distance tempd;
tempd.inch = tempd.feet = 0;
tempd.inch = inch + d1.inch;
if(tempd.inch >= 12){
tempd.inch = tempd.inch - 12;
tempd.feet += 1;
}
tempd.feet += feet + d1.feet;
return tempd;
}
Distance minus(Distance d1)
{
Distance tempd;
tempd.inch = tempd.feet = 0;
tempd.inch = inch - d1.inch;
if(tempd.inch < 0){
tempd.inch = tempd.inch + 12;
tempd.feet --;
}
tempd.feet += feet + d1.feet;
return tempd;
}
void displayDistance(){
cout << "Feet: " << feet << " Inch: " << inch << endl;
}
};
int main()
{
Distance d1, d2, d3;
d1.setDistance(10, 2);
d2.setDistance(30, 10);
d3 = d1.add(d2);
d3.displayDistance();
getch();
return 0;
}