Question: You are given a single file project in simple_class.cpp . It applies OOP for complex number expressions. Then Create a project named Complex by separating

You are given a single file project in simple_class.cppYou are given a single file project in simple_class.cpp. It applies OOP. It applies OOP for complex number expressions. Then Create a project named Complex by separating the single file into multiple files. Contain the class Complex in its own two files, Complex.cpp for the executable code and Complex.h for declarations. Locate main() in a new file, ComplexTest.cpp. (Global variables and constants would normally be located in the corresponding .h file but because there are none in this program no ComplexTest.h is needed.) Build the project and execute test cases to verify it runs.

Please help me!!!

Thank you

#include

#include

#include

#include

#include

using namespace std;

class Complex

{

public:

Complex (double real, double imag);

bool set_cartesian(double real, double imag);

bool set_polar(double magnitude, double angle);

bool get_cartesian(double& real, double& imag);

bool get_polar(double& magnitude, double& angle);

private:

double real_value;

double imaginary_value;

}

int main()

{

Complex complex_a(1.0, 2.0);

Complex complex_b(2.0, 4.0);

double real_value = 0.0;

double imaginary_value = 0.0;

double magnitude = 0.0;

double angle_rads = 0.0;

complex_a.get_cartesian(real_value, imaginary_value);

complex_a.get_polar(magnitude, angle_rads);

cout

cout

cout

cout

complex_b.get_cartesian(real_value, imaginary_value);

complex_b.get_polar(magnitude, angle_rads);

cout

cout

cout

cout

return 0;

} // end of main()

Complex::Complex(double real, double imag)

{

real_value = real;

imaginary_value = imag;

} // end Complex

bool Complex::set_cartesian(double real, double imag)

{

real_value = real;

imaginary_value = imag;

return true;

} // end set_cartesian

bool Complex::set_polar(double magnitude, double angle)

{

real_value = magnitude * cos(angle);

imaginary_value = magnitude * sin(angle);

return true;

} // end set_polar

bool Complex::get_cartesian(double& real, double& imag)

{

real = real_value;

imag = imaginary_value;

return true;

}

bool Complex::get_polar(double& magnitude, double& angle)

{

magnitude = sqrt(real_value * real_value + imaginary_value *

imaginary_value);

angle = atan(imaginary_value / real_value);

return true;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!