Complexes

• 02-19-2003
LePlusMieux
Complexes
I am totally stack on where to start on this. I have these directions:
Develop a class called complex. This class enables operations on so called complex numbers. These are of the form: realPart+imaginaryPart*i

b. Overload the subtraction operator (-) to subtract.
c. Overload the multiplication operator (*) to multiply
d. Overload the division operator (/) to divide
e. Overload the == and != operators for comparisons
f. Overload the operator (<<) to display the complex numbers.

After hours and hours, this is what I got so far:
#include <iostream.h>

class Complex
{
public:
...

Complex operator +(const Complex &op)
{
double real = _real + op._real, imag = _imag + op._imag;
return(Complex(real, imag));
}

...
};

• 02-19-2003
Nautilus
What didn't you now????
You should say, where do tou need help.... Nowbody here will do your work... try fisrt, and then put your realy questions, for get help..
ok???
• 02-19-2003
Nautilus
Sorry my English... ;) I just have some dificulties to write well in english...
• 02-19-2003
nextus
i would do this for you, but 2 things
1) people on this board wouldnt like me very much
2) i have alot of homework tonight but i can get you a head start

Code:

```// some odds and ends class Complex {         public://private:                 double m_Real;                 double m_Img;         public:                 Complex(double Real = 1.0, double Img = 1.0);                 Complex& operator=(const Complex& A);         //e. Overload the == and != operators for comparisons         //f. Overload the operator (<< ) to display the complex numbers. }; // make these yourself Complex operator-(const Complex& A, const Complex& B); Complex operator/(const Complex& A, const Complex& B); Complex operator*(const Complex& A, const Complex& B); // constructor Complex::Complex(double Real, double Img) {         m_Real = Real;         m_Img = Img; } Complex operator+(const Complex& A, const Complex& B) {         return Complex(A.m_Real + B.m_Real, A.m_Img + B.m_Img); } Complex& Complex::operator=(const Complex& A) {         m_Real = A.m_Real;         m_Img = A.m_Img;         return *this; // A + B; also can be made another way }```
remember there is many ways to think of how to overload...many many ways!!!!!! this was my ugly fast thinking and i might be wrong...but i did this in 1 min...hehe