Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a class for complex numbers that will provide the means to store both the

ID: 3644863 • Letter: C

Question

Create a class for complex numbers that will provide the means to store both the real and the imaginary values of a complex number.
Design and add overloaded operators to perform correct and complex mathematical operations on objects of the complex-number class.

Explanation / Answer

Complex Numbers Class #include #include #include #include class complex { private: float real; // Real Part float imag; // Imaginary Part public: complex(float,float); complex(complex&); complex operator +(complex); complex operator -(complex); complex operator *(complex); complex operator /(complex); complex getconjugate(); complex getreciprocal(); float getmodulus(); void setdata(float,float); void getdata(); float getreal(); float getimaginary(); bool operator ==(complex); void operator =(complex); friend ostream& operator imag=c.imag; } void complex::operator =(complex c) { real=c.real; imag=c.imag; } complex complex::operator +(complex c) { complex tmp; tmp.real=this->real+c.real; tmp.imag=this->imag+c.imag; return tmp; } complex complex::operator -(complex c) { complex tmp; tmp.real=this->real - c.real; tmp.imag=this->imag - c.imag; return tmp; } complex complex::operator *(complex c) { complex tmp; tmp.real=(real*c.real)-(imag*c.imag); tmp.imag=(real*c.imag)-(imag*c.real); return tmp; } complex complex::operator /(complex c) { float div=(c.real*c.real) + (c.imag*c.imag); complex tmp; tmp.real=(real*c.real)+(imag*c.imag); tmp.real/=div; tmp.imag=(imag*c.real)-(real*c.imag); tmp.imag/=div; return tmp; } complex complex::getconjugate() { complex tmp; tmp.real=this->real; tmp.imag=this->imag * -1; return tmp; } complex complex::getreciprocal() { complex t; t.real=real; t.imag=imag * -1; float div; div=(real*real)+(imag*imag); t.real/=div; t.imag/=div; return t; } float complex::getmodulus() { float z; z=(real*real)+(imag*imag); z=sqrt(z); return z; } void complex::setdata(float r,float i) { real=r; imag=i; } void complex::getdata() { coutthis->real; coutthis->imag; } float complex::getreal() { return real; } float complex::getimaginary() { return imag; } bool complex::operator ==(complex c) { return (real==c.real)&&(imag==c.imag) ? 1 : 0; } ostream& operator
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote