-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path17.cpp
More file actions
42 lines (35 loc) · 687 Bytes
/
17.cpp
File metadata and controls
42 lines (35 loc) · 687 Bytes
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
//WAP to overload a binary operator ‘+’ to add two values using objects.
#include<iostream>
using namespace std;
class imaginary
{
private:
int a;
int b;
public:
imaginary(int v1)
{
b=v1;
}
void operator+(imaginary obj1)
{
a = b + obj1.b;
}
void printdata(int i)
{
cout<< "Your imaginary No." << i << " " << b << "i\n";
}
void printcomplexsum()
{
cout<< "Sum of Your Complex No. " << a << "i\n";
}
};
int main()
{
imaginary obj0(2),obj1(4);
obj0.printdata(0);
obj1.printdata(1);
obj0+obj1;
obj0.printcomplexsum();
return 0;
}