Hello guys im been tasked to do a series of complex functions. so far im able to complete addition, subtraction and multiplication, but currently stuck at division. Would appreciate any kind soul help on this
class Complex
{
public:
Complex( double r, double i ) : re(r), im(i) {}
Complex operator+( Complex &other );
Complex operator-( Complex &other );
Complex operator*( Complex &other );
Complex operator/( Complex &other );
void Display( )
{
cout << re << " + " << im <<"i"<< endl; }
private:
double re, im; //re = Real Number1, im = Imaginary1, other.re = Real2, other.im = Imaginary2
};
int main()
{
Complex a = Complex(4, 5 ); //given static value for convenience.Actual case will require user to input values.
Complex b = Complex( 3, 2 );
Complex c = Complex( 0,0 );
c = a/b;
c.Display();
system("pause");
}
Division code
int normalize = (other.re * other.re) + (other.im * other.im);//debug denominator
cout<< " Output: "<< normalize<<"test"; //denominator = 13
int testing1=((re * other.re) + (im * other.im));
cout<<"Output of first expression: "<<testing1<<" / "<<normalize<< "Confirmed correct"<<endl; //debug expression 1, 22 is correct answer
int testing2=((im * other.re) - (re * other.im));
cout<<"Output of second expression: " <<testing2<<"testing1";
cout<<" Final Output: "<<testing2<<" / "<<normalize<<"Final test"<<endl;//debug expression 2, +7i is correct answer
return Complex(((re * other.re) + (im * other.im)),
((im * other.re) - (re * other.im))); //debug of expression 1 and 2, 22+7i
}
The equation is correct, however the system keeps displaying its float values after i put in the denominator. For now it only displays 22+7i. My question is, how do i make it such that i can make it display 22+7i/13