To download the code, click here
01: /*
02: * complex.hpp
03: *
04: * Created by D. Kevin McGrath on 11/14/2007.
05: *
06: */
07:
08: #include <iostream>
09: #include <sstream>
10: #include <cmath>
11: #include <string>
12:
13: #ifndef DMCGRATH_COMPLEX_HPP
14: #define DMCGRATH_COMPLEX_HPP
15:
16: namespace dmcgrath{
17:
18: class complex{
19:
20: private:
21: double real_val;
22: double imaginary;
23:
24:
25: public:
26: /*
27: constructors:
28: default: set both real_val and imaginary to 0
29: single parameter: set real_val to parameter value, imaginary to 0
30: two parameters: real_val, imaginary
31: copy: copy constructor
32: */
33: complex();
34:
35: complex(double real_val);
36:
37: complex(double real_val, double imaginary);
38: complex(const complex &c);
39: ~complex();
40:
41: //return the real part
42: const double real();
43: //return the imaginary part
44: const double imag();
45: //flip sign on imaginary part, return a NEW VALUE
46: const complex conj();
47: //overload output operator
48: friend std::ostream& operator<<(std::ostream &os, const complex &c);
49: //overload input operator
50: friend std::istream& operator>>(std::istream &is, complex &c);
51: //absolute value of c
52: double abs();
53: //square absolute value
54: const double norm();
55: //returns the phase angle, in radians
56: double phase();
57:
58: bool operator==(const complex &RHS);
59: bool operator!=(const complex &RHS);
60:
61:
62: bool operator+=(const complex &RHS);
63: bool operator-=(const complex &RHS);
64: bool operator*=(const complex &RHS);
65: bool operator/=(complex &RHS);
66: bool operator=(const complex &RHS);
67: complex operator+(const complex &RHS);
68: complex operator-(const complex &RHS);
69: complex operator*(const complex &RHS);
70: complex operator/(complex &rhs);
71:
72: };
73:
74: }
75:
76: #endif