-
Notifications
You must be signed in to change notification settings - Fork 45
/
op.cpp
59 lines (44 loc) · 1.16 KB
/
op.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
#include<iostream>
#include<string>
using namespace std;
class AddDistance {
private:
int meters;
int centimeters;
public:
void setDistance();
void getDistance();
AddDistance addDistance( AddDistance d );
};
void AddDistance::setDistance() {
cout << " meters: ";
cin >> meters;
cout << "centimeters: ";
cin >> centimeters;
}
void AddDistance::getDistance() {
cout << "meters: " << meters;
cout << " centimeters: " << centimeters;
}
AddDistance AddDistance::addDistance( AddDistance d ) {
AddDistance dist;
dist.meters = meters + d.meters;
dist.centimeters = centimeters + d.centimeters;
if(dist.centimeters>=100)
{
dist.meters+=1;
dist.centimeters-=100;
}
return dist;
}
int main() {
AddDistance d1, d2, d3;
cout << "Enter length of Distance 1: " << endl;
d1.setDistance();
cout << "Enter length of Distance 2: " << endl;
d2.setDistance();
d3 = d1.addDistance(d2);
cout << "Sum of Distance 1 and Distance 2:" << endl;
d3.getDistance();
return 0;
}