me again lol, got another assignment i'm stuck on, The main body of the program is done, i just need to fill in the functions and make the main.
Create a class called Complex that represents a complex number. You should provide the following functionality:
* a default constructor that makes it 0
* a constructor that allows the setting of the real and imaginary parts
* a method to produce the conjugate
* operators for addition, subtraction, multiplication, and division
* an operator for printing to a stream
You should also create a main function that tests all of this functionality.
What i have so far.
Code:#include <iostream> using namespace std; class Complex { friend Complex operator+(Complex lhs, Complex rhs); friend Complex operator-(Complex lhs, Complex rhs); friend Complex operator*(Complex lhs, Complex rhs); friend Complex operator/(Complex lhs, Complex rhs); friend ostream& operator<<(ostream& lhs, Complex rhs); // 2+3i 5-6i 4 2i 0 private: double real; double imag; public: Complex(); // Should become 0. Complex(double r, double i); Complex conjugate(); double getReal() { return real; } double getImag() { return imag; } }; Complex::Complex() { real = imag = 0; } Complex::Complex(double r, double i) { real = r; imag = i; } Complex Complex::conjugate() { Complex c(real, -imag); return c; } //(a+bi) + (c+di) = (a+c) + (b+d)i Complex operator+(Complex lhs, Complex rhs) { } //(a+bi) - (c+di) = (a-c) + (b-d)i Complex operator-(Complex lhs, Complex rhs) { } //(a+bi) * (c+di) = (ac-bd) + (bc+ad)i Complex operator*(Complex lhs, Complex rhs) { } // (a+bi) / (c+di) = Complex operator/(Complex lhs, Complex rhs) { } ostream& operator<<(ostream& lhs, Complex rhs) { }
XI Wiki


