complex.h
1.17 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
#ifndef __Complex_H__
#define __Complex_H__
#include <iostream>
#include <math.h>
using namespace std;
class Complex
{
private:
double Real, Imag;
public:
Complex ():Real (0), Imag (0)
{
};
Complex (double co)
{
Real = co;
Imag = 0;
};
Complex (double Real, double Imag)
{
this->Real = Real;
this->Imag = Imag;
};
Complex & operator= (const Complex & s)
{
Real = s.Real;
Imag = s.Imag;
return *this;
};
Complex operator- () const
{
return Complex(-Real,-Imag);
};
Complex & operator= (double co)
{
Real = co;
Imag = 0;
return *this;
};
Complex operator+ (const Complex& co) const
{
Complex n;
n.Real = this->Real + co.Real;
n.Imag = this->Imag + co.Imag;
return n;
};
Complex & operator-= (Complex co)
{
Real -= co.Real;
Imag -= co.Imag;
return *this;
};
friend Complex operator- (Complex, Complex);
friend ostream & operator << (ostream & s, const Complex & c)
{
s << "(" << c.Real << "," << c.Imag << ")";
return s;
};
};
inline Complex
operator - (Complex s1, Complex s2)
{
Complex n (s1);
return n -= s2;
}
#endif /* __Complex_H__ */