Complex Number C++

Can anyone help me?

I got a task from my lecturer to make a program about "complex number" with 4 operating ( - , + , x , : )
Can anyone help me?


Can you please start?
And when you are stuck, then we will help.
Here's a starter...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class mcomplex
{
	double real;
	double imag;
	
	public:
	mcomplex operator+(mcomplex &z);
	mcomplex operator-(mcomplex &z);
	mcomplex operator*(mcomplex &z);
	mcomplex operator/(mcomplex &z);
};

mcomplex mcomplex::operator+(mcomplex &z)
{
	mcomplex rz;
	// ...
	return rz;
}

mcomplex mcomplex::operator*(mcomplex &z)
{
	// ...
}

// ... 
Last edited on
Umm.. okay you started but still quite far.

I am going to tell you just how to add and multiply the complex numbers, coding is upto you.
Let,
A = a + ib ; B = x + iy
be two complex numbers. Then
A + B = (a+x) + i(b+y)
A * B = (ax - by) + i(ay + bx)

Now use these formulas and try writing the code.
Last edited on
Aceix -> I had tried and I got problem with ":" operate

ToniAz -> Yes, thanks a lot. But now, I get problem with ":" operate

Amol Bhave -> Do you know about ":" formula?
Post your code.
':' is not an operator for mathematical calculations AFAIK.
It is used in conjunction with the conditional operator(?) eg:

a=b ? cout<<"a is equal to b" : cout<<"a is not equal to b";

This means, if a=b, it would execute the statement before the colon otherwise, the statement after the colon
But now, I get problem with ":" operate

Just wondering whether the OP did

mcomplex:operator+ one colon

instead of

mcomplex::operator+ two colons.
Aceix and TheIdeas Man -> I'm Sorry, I mean the division or split operate. For Ex. : (a + bi) / (c + di), what is the formula?
formula for?
Formula for (a + bi) / (c + di).

This is your formula before :
A + B = (a+x) + i(b+y)
A * B = (ax - by) + i(ay + bx)

but now, I need a formula for division or split operate. (a + bi) / (c + di).
Ok. You want a complex one huh?

Take this: double num=A/B*(b*y)+5/(i*9)
The thing is the programme and how to make complex 'stuff' is in your hands.

But you can do something like the user entering a complex number, then you use formulas to give him a result. eg: Calculating force. The user enters the mass of the object, then your programme uses the formula for calculating force, to give the user an answer.

I can help with something like this....what do you say?
Hahaha, thank you very much. Your answer was very helpful. Now, my task is almost complete. I hope you can help me again. Hehehe
@aceix:
a=b ? cout<<"a is equal to b" : cout<<"a is not equal to b";
it should be: a == b
@chipp
Yeah, didn't see that one

@Zumphex
Never mind always READY! ... HAHAHAAA like a soldier.
Last edited on
Topic archived. No new replies allowed.