Program about Complex numbers.

...
Last edited on
I would design it like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
template <typename T>
class Complex {
public:
    Complex(T const &real) : real(real), imaginary(0) { }
    Complex(T const &real, T const &imaginary) :
    real(real), imaginary(imaginary) { }
    
    friend T const & Re<> (Complex<T> const &z);
    friend T const & Im<> (Complex<T> const &z);
    
    Complex<T> operator+ (Complex<T> const &z)
    {
        return Complex<T>(real + z.real, imaginary + z.imaginary);
    }    
    Complex<T> operator* (Complex<T> const &z)
    {
        return Complex<T>(real * z.real - imaginary * z.imaginary,
                          real * z.imaginary + imaginary * z.real);
    }
    
private:
    T real;
    T imaginary;
};
Last edited on
I would stay away from templates just yet. Keep it as simple as possible. Your class needs to have only two double variables: the real and the imaginary parts.

Good luck!
...
Last edited on
So Far I have this much in the program. Am I in the right track? And I do have a lot of errors. So can you check please?
It is really hard to evaluate code that is not in [code] tags and properly indented.
...
Last edited on
How can I indent my code because whenever I copy paste it. It happens the same shit.
rootsline1 wrote:
How can I indent my code because whenever I copy paste it. It happens the same shit.


put it between a pair of [code] [/code] tags.
rootsline1, yes, basically, you are on a right track. However, your present code contains a dozen of syntax errors like c6(5,6,). Try to get rid of them first.

It is much better to use a template to avoid hardcored data type. You are using float one. Right? However, it is not the only choice. A complex number might compose integer or double precision real.
Last edited on
If you're still needing help on this topic I suggest you stop erasing the history of your posts. No one else can jump in to help you now since we can't see the original question.
Topic archived. No new replies allowed.