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

40 points) You are handed a C++ header file named complex.h. Inside, you find th

ID: 3906290 • Letter: 4

Question

40 points) You are handed a C++ header file named complex.h. Inside, you find the following skeletal C++ class for a complex number with rectangular coordinates: wifndef COMPLEX M adefine cOMPLEX H class complex public: protected: double real; double imag; l: #endif Modify the class declaration above to include the following PUBLIC methods: The Orthodox Canonical Form (0CF); You may implement the trivial methods in the declaration. Accessor Functions; A class method which takes a reference to another instance of the class as a parameter and calculates the magnitude of the vector between the two instances. The method may not modify either instance in any way. A class method which takes a reference to another instance of the class as a parameter and calculates the phasor angle of the vector between the two instances. The method may not modify either instance in any way. . .

Explanation / Answer

Class Complex

{

public:

//OCF methods

complex(){}//default constructor

Complex(Complex & X) //copy constructor

{

real=X.real;

imag=X.imag;

}

Complex(double a, double b) //parameterized construtor

{

real =a;

imag =b;

}

~complex()   //destructor

{

Cout<<” Object Destroyed”;

}

Complex & operator=( const Complex & X) //assignment operator

{

real=X.real;

imag=X.imag;

return * this;

}

//OCF methods end

//Accessor functions

void set(double a, double b)

{

real=a;

imag=b;

}

void get()

{

cout<<”real=”<<real;

cout<<”imag=”<<imag;

}

//Accessor functione ends

double calculatemagnitude( const Complex & X)

{

double magnitude;

magnitude =sqrt ((X.real-real)2 +(X.imag-imag)2)

return magnitude;

}

double calculatephasorangle( const Complex & X)

{

double phasor;

phasor= Math.atan2(X.imag-imag, X.real-real)

return phasor;

}

protected:

double real;

double imag;

};

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