-
Notifications
You must be signed in to change notification settings - Fork 0
/
complex.h
87 lines (47 loc) · 1.75 KB
/
complex.h
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
#ifndef COMPLEX_H
#define COMPLEX_H
#include <iostream>
using namespace std;
class complex {
private:
double r, i;
public:
complex();
explicit complex(double real, double imaginary = 0);
complex(const complex &other) = default;
double real() const;
double imaginary() const;
complex &real(double real);
complex &imaginary(double imaginary);
double abs() const;
complex complement() const;
void print() const;
complex operator-(); // Negative
complex operator~(); // Complement
complex operator+(const complex &rhs);
complex operator-(const complex &rhs);
complex operator*(const complex &rhs);
complex operator/(const complex &rhs);
complex operator+(const double &rhs);
complex operator-(const double &rhs);
complex operator*(const double &rhs);
complex operator/(const double &rhs);
complex &operator=(const complex &rhs) = default;
complex &operator+=(const complex &rhs);
complex &operator-=(const complex &rhs);
complex &operator*=(const complex &rhs);
complex &operator/=(const complex &rhs);
complex &operator=(const double &rhs);
complex &operator+=(const double &rhs);
complex &operator-=(const double &rhs);
complex &operator*=(const double &rhs);
complex &operator/=(const double &rhs);
friend complex operator+(const double &lhs, const complex &rhs);
friend complex operator-(const double &lhs, const complex &rhs);
friend complex operator*(const double &lhs, const complex &rhs);
friend complex operator/(const double &lhs, const complex &rhs);
friend ostream &operator<<(ostream &out, const complex &c);
friend istream &operator>>(istream &in, complex &c);
~complex() = default;
};
#endif