Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.cppimage text in transcribed. 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions

Question

Developing and delivering learning that is integrated with the job.

Answered: 1 week ago

Question

Use of assessments to determine trainees learning styles.

Answered: 1 week ago