/*************************************************************************
 * complex.h
 *
 * Header file for an implementation of complex numbers using operator
 * overloading. Features overloading of basic arithmetic and comparison.
 *
 * Written by Paul Bonamy - 8 June 2010
 ************************************************************************/

#ifndef COMPLEX_H
#define COMPLEX_H

#include <iostream>     // provides the ostream def for the output op
using namespace std;

/*************************************************************************
 * Relatively simple complex number class
 * Provides basic arithmetic and comparison overloading
 ************************************************************************/

class Complex {
    public:
        // constructors
        Complex();                      // default
        Complex(double r, double i);    // rpart and ipart given
        Complex(double r);              // only rpart given
        
        // no dynamic memory == no need for a destructor
        
        // the output operator always has to be global, so friend it
        friend ostream& operator<< ( ostream & out, const Complex & c);
        
        // operators overloaded as member functions
        Complex& operator= (const Complex & c); // assignment
        
        // basic (non-modifying) arithmetic
        const Complex operator+ (const Complex & c) const; // addition
        const Complex operator- (const Complex & c) const; // subtraction
        const Complex operator* (const Complex & c) const; // multiplication
        const Complex operator/ (const Complex & c) const; // division
        
        // self-modifying arithmetic
        Complex& operator+= (const Complex & c); // addition
        Complex& operator-= (const Complex & c); // subtraction
        Complex& operator*= (const Complex & c); // multiplication
        Complex& operator/= (const Complex & c); // division
        
        // comparison operators
        bool operator== (const Complex & c) const; // equality
        bool operator!= (const Complex & c) const; // inequality
        bool operator> (const Complex &c) const; // greater-than
        bool operator< (const Complex &c) const; // less-than
        bool operator>= (const Complex &c) const; // greater-than-or-equal
        bool operator<= (const Complex &c) const; // less-than-or-equal
        
        // these are here to make the class more useful for other things
        double abs();   // absolute value aka modulus, magniture
        Complex conj(); // complex conjugate
        
        // getter methods for the parts of the Complex
        double re() { return rpart; }
        double im() { return ipart; }

    private:
        double rpart;   // real part
        double ipart;   // imaginary part
};

#endif