November 1999
Intermediate to advanced
336 pages
6h 29m
English
The Complex class implements a representation for complex numbers:
class Complex
{
// Complex addition operator
friend Complex operator+(const Complex&, const Complex&);
public:
// Default constructor.
// Value defaults to 0 unless otherwise specified.
Complex (double r = 0.0, double i = 0.0) : real (r), imag (i) {}
// Copy constructor
Complex (const Complex& c) : real (c.real), imag (c.imag) {}
// Assignment operator
Complex& operator= (const Complex& c);
~Complex() {}
private:
double real;
double imag;
};
The addition operator returns a Complex object by value, as in:
Complex operator+ (const Complex& a, const Complex& b) { Complex retVal; retVal.real = a.real + b.real; retVal.imag = a.imag + b.imag; return ...Read now
Unlock full access