-
Notifications
You must be signed in to change notification settings - Fork 1
/
complex.h
81 lines (64 loc) · 2.34 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
/*
This header file provides functionality of complex numbers through class Complex
The following functions are supported:
1. real() : returns real part of the complex number
2. imag() : returns imaginary part of the complex number
3. mod() : returns modulus of the complex number
4. arg() : returns argument of the complex number (in radians)
5. argInDegrees() : returns argumnt of the complex number (in degrees)
The following operators are supported (both with other complex numbers and real constants):
+, -, *, /, +=, -=, *=, /=, <<, >> (output/input)
Two unary operators are also supported:
! (returns conjugate of the complex number)
- (unary minus, returns negative of a complex number)
*/
#ifndef _COMPLEX_NUMBERS_H_
#define _COMPLEX_NUMBERS_H_
#include<cmath>
#include<iostream>
#include<string>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
class Complex{
double realPart, imaginaryPart;
public:
Complex();
Complex(double real);
Complex(double real, double imaginary);
void setReal(double real);
void setImag(double imag);
bool operator == (Complex other);
bool operator != (Complex other);
Complex operator + (Complex other);
void operator += (Complex other);
Complex operator + (double other);
void operator += (double other);
friend Complex operator + (double a, Complex C);
Complex operator - (Complex other);
void operator -= (Complex other);
Complex operator - (double other);
void operator -= (double other);
friend Complex operator - (double a, Complex C);
Complex operator * (Complex other);
void operator *= (Complex other);
Complex operator * (double other);
void operator *= (double other);
friend Complex operator * (double a, Complex C);
Complex operator / (Complex other);
void operator /= (Complex other);
Complex operator / (double other);
void operator /= (double other);
friend Complex operator / (double a, Complex C);
Complex operator -();
Complex operator !();
double real();
double imag();
double mod();
double arg();
double argInDegrees();
friend std::ostream& operator << (std::ostream &output, Complex C);
static double stringToDouble(std::string toConvert);
friend std::istream& operator >> (std::istream &input, Complex &C);
};
#endif