-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoop.cpp
More file actions
69 lines (60 loc) · 1.02 KB
/
Copy pathoop.cpp
File metadata and controls
69 lines (60 loc) · 1.02 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
#include <iostream>
using namespace std;
class Complex
{
float real;
float imag;
public:
void setReal(float i)
{
real = i;
};
void setImag(float i)
{
imag = i;
};
float getReal()
{
return real ;
};
float getImag()
{
return imag ;
};
void print()
{
if(imag < 0)
{
cout << real << " - " << abs(imag) << "i" << endl;
}
else
{
cout << real << " + " << abs(imag) << "i" << endl;
}
};
Complex add(Complex c)
{
Complex temp;
temp.real = real + c.real;
temp.imag = imag + c.imag;
return temp;
} ;
Complex subtract(Complex c)
{
Complex temp;
temp.real = real - c.real;
temp.imag = imag - c.imag;
return temp;
} ;
};
int main()
{
Complex c1,c2,c3;
c1.setReal(7);
c1.setImag(2);
c2.setReal(5);
c2.setImag(5);
c3 = c1.add(c2);
c3.print();
return 0;
}