-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComplex.hxx
More file actions
122 lines (105 loc) · 2.06 KB
/
Complex.hxx
File metadata and controls
122 lines (105 loc) · 2.06 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "Complex.hpp"
#include <iostream>
#include <cmath>
Complex::Complex()
{
real_ = 0;
imag_ = 0;
}
Complex::Complex(double real, double imag)
{
real_ = real;
imag_ = imag;
}
Complex::Complex(const Complex& z1)
{
real_ = z1.real_;
imag_ = z1.imag_;
}
Complex& Complex::operator=(const Complex& z1)
{
if (*this != z1)
{
real_ = z1.real_;
imag_ = z1.imag_;
}
return *this;
}
Complex Complex::Conjugate()
{
Complex conjugate = Complex(real_, (imag_*-1));
return conjugate;
}
double Complex::GetReal() const
{
return real_;
}
double Complex::GetImag() const
{
return imag_;
}
double Complex::Absolute() const
{
return sqrt((real_ * real_) + (imag_ * imag_));
}
double Complex::Distance(const Complex& z1) const
{
Complex difference = Complex(real_, imag_);
difference = difference - z1;
return difference.Absolute();
}
void Complex::SetReal(double real)
{
real_ = real;
}
void Complex::SetImag(double imag)
{
imag_ = imag;
}
void Complex::Print() const
{
std::cout << real_ << " + " << imag_ << "i\n";
}
bool Complex::operator==(const Complex& z1) const
{
if (real_ == z1.real_ && imag_ == z1.imag_)
{
return true;
}
else
{
return false;
}
}
bool Complex::operator!=(const Complex& z1) const
{
if (real_ != z1.real_ || imag_ != z1.imag_)
{
return true;
}
else
{
return false;
}
}
Complex Complex::operator+(const Complex& z1) const
{
Complex sum = Complex(real_, imag_);
sum.real_ = sum.real_ + z1.real_;
sum.imag_ = sum.imag_ + z1.imag_;
return sum;
}
Complex Complex::operator-(const Complex& z1) const
{
Complex diff = Complex(real_, imag_);
diff.real_ = diff.real_ - z1.real_;
diff.imag_ = diff.imag_ - z1.imag_;
return diff;
}
Complex Complex::operator*(const Complex& z1) const
{
Complex prod = Complex(real_, imag_);
prod.real_ = (prod.real_ * z1.real_) - (z1.imag_ * prod.imag_);
prod.imag_ = (prod.real_ * z1.imag_) + (z1.imag_ * prod.real_);
return prod;
}