-
Notifications
You must be signed in to change notification settings - Fork 0
/
a1.7.cpp
69 lines (49 loc) · 1.16 KB
/
a1.7.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* 7.
* WAP in CPP to find the sum of two distance object with feet and inch as
* the members.
*/
#include <iostream>
using namespace std;
class Distance {
int feet, inch;
public:
Distance(){
feet = 0;
inch = 0;
}
void getDistance(){
cin >> this->feet >> this->inch;
}
void displayResult(){
cout << "Final Output: "
<< this->feet << " ft "
<< this->inch << " inch" << endl;
}
Distance sum(Distance, Distance);
~Distance(){};
};
Distance Distance::sum(Distance dist1, Distance dist2){
Distance tmp;
int d1, d2;
d1 = dist1.feet + dist2.feet;
d2 = dist1.inch + dist2.inch;
const int d3 = d2/12;
if (d3 > 0){
d1 += d3;
d2 -= 12*d3;
}
tmp.feet = d1;
tmp.inch = d2;
return tmp;
}
int main(){
Distance distance1, distance2, distance3;
cout << "Enter distance in feet and inch: ";
distance1.getDistance();
cout << "Enter another distance in feet and inch: ";
distance2.getDistance();
distance3 = distance3.sum(distance1, distance2);
distance3.displayResult();
return 0;
}