-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoo3.cpp
More file actions
86 lines (85 loc) · 1.26 KB
/
oo3.cpp
File metadata and controls
86 lines (85 loc) · 1.26 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
84
85
86
#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;
}
friend weight operator + (weight w1,weight w2);
friend weight operator - (weight w1,weight w2);
friend weight operator ++ (weight w1);
friend weight operator -- (weight w1);
//friend weight operator = (weight w1,weight w2);
void show()
{
cout<<kg<<" kilogram(s) "<<gr<<" gram(s)\n";
}
};
weight operator + (weight w1,weight w2)
{
weight temp;
temp.kg=w1.kg+w2.kg;
temp.gr=w1.gr+w2.gr;
if (temp.gr>1000)
{
temp.gr%=1000;
temp.kg+=1;
}
cout<<temp.kg<<temp.gr;
return temp;
}
weight operator - (weight w1,weight w2)
{
weight temp;
temp.kg=w1.kg-w2.kg;
temp.gr=w1.gr-w2.gr;
return temp;
}
weight operator ++ (weight w)
{
weight temp;
temp.kg=++w.kg;
temp.gr=++w.gr;
return temp;
}
weight operator -- (weight w)
{
weight temp;
temp.kg=--w.kg;
temp.gr=--w.gr;
return temp;
}
/*weight operator = (weight w1,weight w2)
{
weight temp;
w1.kg=w2.kg;
temp.kg=w1.kg;
w1.gr=w2.gr;
temp.gr=w1.gr;
return temp;
}*/
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;
}