-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpracticeques.cpp
More file actions
90 lines (88 loc) · 1.57 KB
/
practiceques.cpp
File metadata and controls
90 lines (88 loc) · 1.57 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
87
88
89
90
// not to write in lab record
// Experiment a Program in C++ Overload Binary operators (+,-,*, /)
#include <iostream>
using namespace std;
class demo
{
private:
int a, b;
public:
void input()
{
cout << "Enter value of a & b\n";
cin >> a >> b;
}
demo operator+(demo obj)
{
demo temp;
temp.a = a + obj.a;
temp.b = b + obj.b;
return temp;
}
demo operator-(demo obj)
{
demo temp;
temp.a = a - obj.a;
temp.b = b - obj.b;
return temp;
}
demo operator*(demo obj)
{
demo temp;
temp.a = a * obj.a;
temp.b = b * obj.b;
return temp;
}
demo operator/(demo obj)
{
demo temp;
temp.a = a / obj.a;
temp.b = b / obj.b;
return temp;
}
void show()
{
cout << "a = " << a << endl
<< "b = " << b << endl;
}
};
int main()
{
class demo A, B, C, D, E, F;
cout << "Enter value for object A\n";
A.input();
cout << "Enter value for object B\n";
B.input();
C = A + B;
cout << "A + B = " << endl;
C.show();
D = A - B;
cout << "A - B = " << endl;
D.show();
E = A * B;
cout << "A * B = " << endl;
E.show();
F = A / B;
cout << "A / B = " << endl;
F.show();
return 0;
}
// Output:
// Enter value for object A
// Enter value of a & b
// 6 5
// Enter value for object B
// Enter value of a & b
// 3 2
// A + B =
// a = 9
// b = 7
// A - B =
// a = 3
// b = 3
// A * B =
// a = 18
// b = 10
// A / B =
// a = 2
// b = 2