-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplex.cpp
More file actions
51 lines (38 loc) · 755 Bytes
/
Copy pathcomplex.cpp
File metadata and controls
51 lines (38 loc) · 755 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
43
44
45
46
47
48
49
50
51
#include <iostream>
using namespace std;
class Complex
{
private:
int real, imaginary;
public:
Complex(int r = 0, int i = 0)
{
real = r;
imaginary = i;
}
friend Complex operator+(const Complex &, const Complex &);
void display()
{
cout << real << " + " << imaginary << "i" << endl;
}
};
Complex operator+(const Complex &c1, const Complex &c2)
{
Complex temp;
temp.real = c1.real + c2.real;
temp.imaginary = c1.imaginary + c2.imaginary;
return temp;
}
int main()
{
Complex c1(4, 5);
Complex c2(2, 3);
Complex sum = c1 + c2;
cout << "c1 = ";
c1.display();
cout << "c2 = ";
c2.display();
cout << "Sum = ";
sum.display();
return 0;
}