-
Notifications
You must be signed in to change notification settings - Fork 0
/
mycomplex.cpp
64 lines (55 loc) · 1.2 KB
/
mycomplex.cpp
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
#include "mycomplex.h"
MyComplex::MyComplex(double r, double i)
{
real = r;
image = i;
}
MyComplex::MyComplex(const MyComplex &c)
{
real = c.real;
image = c.image;
}
double MyComplex::getReal(void) const
{
return real;
}
double MyComplex::getImage(void) const
{
return image;
}
void MyComplex::setComplex(double r, double i)
{
real = r;
image = i;
}
//QDebug& operator<<(QDebug& out, const MyComplex& c)
//{
// if(c.image>0)
// out<<c.real<<'+'<<c.image<<'i';
// if(c.image<0)
// out<<c.real<<'-'<<c.image<<'i';
// if(c.image==0)
// out<<c.real;
// return out;
//}
MyComplex operator+(const MyComplex& c1, const MyComplex& c2)
{
MyComplex t;
t.real = c1.real + c2.real;
t.image = c1.image + c2.image;
return t;
}
MyComplex operator-(const MyComplex& c1, const MyComplex& c2)
{
MyComplex t;
t.real = c1.real - c2.real;
t.image = c1.image - c2.image;
return t;
}
MyComplex operator*(const MyComplex& c1, const MyComplex& c2)
{
MyComplex t;
t.real = c1.real*c2.real - c1.image*c2.image;
t.image = c1.image*c2.real + c1.real*c2.image;
return t;
}