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: 3906282 • 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

Given below is the code for the question.
Please do rate the answer if it was helpful. Thank you

#ifndef COMPLEX_H
#define COMPLEX_H
#include <iostream>
#include <cmath>

class Complex
{
public:
//default constructor
Complex(){ real = imag = 0;}

//copy constructor
Complex(const Complex& other){*this = other;}

//assignment operator
Complex& operator =(const Complex& other) {
real = other.real;
imag = other.imag;
return *this;
}

//destructor
~Complex(){}

//Accessors
double getReal(){ return real;}
double getImage(){ return imag;}

//Mutators
void setReal(double r){real = r;}
void setImag(double i) {imag = i;}

//method to return lenght of vector
double vectorLength(const Complex& other){
double dr = real - other.real;
double di = imag - other.imag;
return sqrt(dr * dr + di * di);
}

//method to return phasor angle in radians
double phasorAngle(const Complex& other){
double dx = real - other.real;
double dy = imag - other.imag;
return atan(dy/dx);
}

protected:
double real;
double imag;
};
#endif

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