Sep 18, 2012 at 10:26am UTC
Can anyone help me?
I got a task from my lecturer to make a program about "complex number" with 4 operating ( - , + , x , : )
Sep 18, 2012 at 1:23pm UTC
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 Sep 18, 2012 at 1:23pm UTC
Sep 18, 2012 at 2:01pm UTC
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 Sep 18, 2012 at 2:02pm UTC
Sep 19, 2012 at 7:51am UTC
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?
Sep 19, 2012 at 8:00am UTC
':' 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
Sep 19, 2012 at 8:04am UTC
But now, I get problem with ":" operate
Just wondering whether the OP did
mcomplex:operator +
one colon
instead of
mcomplex::operator +
two colons.
Sep 19, 2012 at 10:20am UTC
Aceix and TheIdeas Man -> I'm Sorry, I mean the division or split operate. For Ex. : (a + bi) / (c + di), what is the formula?
Sep 19, 2012 at 10:35am UTC
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).
Sep 19, 2012 at 10:44am UTC
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?
Sep 19, 2012 at 12:24pm UTC
Hahaha, thank you very much. Your answer was very helpful. Now, my task is almost complete. I hope you can help me again. Hehehe
Sep 19, 2012 at 1:38pm UTC
@aceix:
a=b ? cout<<"a is equal to b" : cout<<"a is not equal to b" ;
it should be: a == b
Sep 19, 2012 at 3:41pm UTC
@chipp
Yeah, didn't see that one
@Zumphex
Never mind always READY! ... HAHAHAAA like a soldier.
Last edited on Sep 19, 2012 at 3:49pm UTC