-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoo2.cpp
More file actions
83 lines (82 loc) · 1.04 KB
/
oo2.cpp
File metadata and controls
83 lines (82 loc) · 1.04 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "iostream"
using namespace std;
class weight
{
int kg,gr;
public:
weight()
{
kg=0;
gr=0;
}
weight(int k,int g)
{
kg=k;gr=g;
}
weight operator + (weight w)
{
weight temp;
temp.kg=kg+w.kg;
temp.gr=gr+w.gr;
if (temp.gr>1000)
{
temp.gr%=1000;
temp.kg+=1;
}
cout<<temp.kg<<temp.gr;
return temp;
}
weight operator - (weight w)
{
weight temp;
temp.kg=kg-w.kg;
temp.gr=gr-w.gr;
return temp;
}
weight operator ++ ()
{
weight temp;
++kg;
temp.kg=kg;
++gr;
temp.gr=gr;
return temp;
}
weight operator -- ()
{
weight temp;
temp.kg=--kg;
temp.gr=--gr;
return temp;
}
weight operator = (weight w)
{
weight temp;
kg=w.kg;
temp.kg=kg;
gr=w.gr;
temp.gr=gr;
return temp;
}
void show()
{
cout<<kg<<" kilogram(s) "<<gr<<" gram(s)\n";
}
};
int main()
{
weight w1(7,900);
weight w2(5,300);
weight w3;
w3=w2+w1;
w3.show();
w3=w1-w2;
w3.show();
w3=++w2;
w3.show();
w3=--w1;
w3.show();
w3=w2;
w3.show();
return 0;
}