Complex
models a complex number of the form z = a + ib
where:
a
is a real number.b
is a real number.
Implement Complex
according to the following specification:
Method | Description | Usage | Exceptions |
---|---|---|---|
Complex() |
Constructs a complex number with no real and no imaginary component. |
|
None |
Complex(double const& real) |
Constructs a complex number with a real component but no imaginary component. |
|
None |
Complex(double const& real, double const& imaginary) |
Constructs a complex number with a real and imaginary component. |
|
None |
~Complex() |
Destructor. |
|
None |
Complex conjugate() |
Returns the conjugate of *this . |
|
None |
double modulus() |
Returns the modulus of *this
|
|
None |
double argument() |
Returns the argument of *this . |
|
None |
In addition to the above specification, you must:
- Implement
const
-correctness for methods and member variables. - Mark the default constructor as
default
ordelete
. - Mark the destructor as
default
ordelete
. - Use initialiser lists where required.
- Use delegating constructors where possible.
- Have correct access specifiers.
Take the Complex
class from lab02-1 and extend it with the following specification:
Method | Description | Usage | Exceptions |
---|---|---|---|
Complex(Complex const& z) |
Copy constructor. |
|
None |
Complex(Complex&& z) |
Move constructor. |
|
None |
Complex& operator=(Complex const& z) |
Copy assignment. |
|
None |
Complex& operator=(Complex&& z) |
Move assignment. |
|
None |
static Complex make_conjugate(Complex const& z) |
Returns the conjugate of z . Equivalent to z.conjugate() . |
|
None |
friend Complex operator+(Complex const& lhs, Complex const& rhs) |
Returns the addition of two complex numbers. |
|
None |
friend Complex operator-(Complex const& lhs, Complex const& rhs) |
Returns the subtraction of two complex numbers. |
|
None |
friend Complex operator*(Complex const& lhs, Complex const& rhs) |
Returns the multiplication of two complex numbers. |
|
None |
friend bool operator==(Complex const& lhs, Complex const& rhs) |
Returns true if real components are equal and imaginary components equal. |
|
None |
friend bool operator!=(Complex const& lhs, Complex const& rhs) |
Returns false if real components are equal and imaginary components equal. |
|
None |
friend std::ostream& operator<<(std::ostream& os, Complex const& z) |
Writes the complex number to the output in the format a+bi where a and b are the real and imaginary component respectively. |
|
None |
In addition to the above specification, you must:
- Implement
const
-correctness for methods and member variables. - Mark appropriate constructors, assignments, and destructor as
default
ordelete
. - Have correct access specifiers.
- Write more tests for the new methods.