complexnumber

#include<cmath>
class ComplexNumber{
private:
float Re, Im;
public:
ComplexNumber(float NewRe, float NewIm){
Re = NewRe;
Im = NewIm;
}
ComplexNumber(float NewRadius, float NewTheta, char c){
Re = NewRadius * cos(NewTheta);
Im = NewRadius * sin(NewTheta);
}
ComplexNumber(){
Re = 0;
Im = 0;
}
ComplexNumber Add(ComplexNumber AnotherNumber){
return(
ComplexNumber(
Re+AnotherNumber.Re,
Im+AnotherNumber.Im
)
);
}
ComplexNumber operator +(ComplexNumber AnotherNumber){
return(
ComplexNumber(
Re+AnotherNumber.Re,
Im+AnotherNumber.Im
)
);
}
ComplexNumber Sub(ComplexNumber AnotherNumber){
return(
ComplexNumber(
Re-AnotherNumber.Re,
Im-AnotherNumber.Im
)
);
}
ComplexNumber operator -(ComplexNumber AnotherNumber){
return(
ComplexNumber(
Re-AnotherNumber.Re,
Im-AnotherNumber.Im
)
);
}
ComplexNumber operator *(ComplexNumber AnotherNumber){
return(
//option 1
//ComplexNumber(
// Re*AnotherNumber.Re-Im*AnotherNumber.Im,
// Im*AnotherNumber.Re+Re*AnotherNumber.Im
//)
//option 2
ComplexNumber(
Radius() * AnotherNumber.Radius(),
Theta() + AnotherNumber.Theta(),
0
)
);
}
float Radius(){
return(sqrt(Re*Re+Im*Im));
}
float Theta(){
return(atan(Im/Re));
}
};
void main(){
ComplexNumber a(1,1), b(2,1), c;
c = a-a;
}
// trying to Finnish this program but i got stuck. Not sure what i should put after this...any ideas would be great
What are you trying to achieve?

What problems are you having?

Oh, and please enclose your code in code tags, to make it more readable. Use the "<>" button to the right of the edit window.
Topic archived. No new replies allowed.