-
Notifications
You must be signed in to change notification settings - Fork 0
/
Complex.cpp
54 lines (39 loc) · 1.22 KB
/
Complex.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
#include "Complex.h"
using namespace std;
ostream &operator<<(ostream &out, const Complex &c) {
out << "(" << c.getReal() << "," << c.getImaginary() << ")";
return out;
}
Complex operator+(const Complex &c1, const Complex &c2) {
return Complex(c1.getReal()+c2.getReal(), c1.getImaginary()+c2.getImaginary());
}
Complex operator+(const Complex &c1, double d) {
return Complex(c1.getReal()+d, c1.getImaginary());
}
Complex operator+(double d, const Complex &c1) {
return Complex(c1.getReal()+d, c1.getImaginary());
}
Complex::Complex(void): real(0), imaginary(0)
{
}
Complex Complex::operator*() const {
return Complex(real, -imaginary);
}
Complex::Complex(double real, double imaginary) : real(real), imaginary(imaginary) {
}
Complex::Complex(const Complex &other) {
//cout << "Copy" << endl;
real = other.real;
imaginary = other.imaginary;
}
const Complex &Complex::operator=(const Complex &other) {
real = other.real;
imaginary = other.imaginary;
return *this;
}
bool Complex::operator==(const Complex &other) const {
return (real == other.real) && (imaginary == other.imaginary);
}
bool Complex::operator!=(const Complex &other) const {
return !(*this==other);
}