Question: NOTE: THE ONLY FILE THAT NEEDS TO BE CHANGED IS COMPLEX_NUMBER.CPP. COMPLEX_NUMBERS.H #ifndef COMPLEX_NUMBER_H #define COMPLEX_NUMBER_H class complex_number { public: complex_number (double r = 0.0,

NOTE: THE ONLY FILE THAT NEEDS TO BE CHANGED IS COMPLEX_NUMBER.CPP. NOTE: THE ONLY FILE THAT NEEDS TO BE CHANGED IS COMPLEX_NUMBER.CPP. COMPLEX_NUMBERS.H COMPLEX_NUMBERS.H #ifndef COMPLEX_NUMBER_H

#define COMPLEX_NUMBER_H

class complex_number { public: complex_number (double r = 0.0, double i = 0.0); // postcondition: complex with given components has been created double get_real_part () const; // returned: real part of complex number double get_imag_part () const; // returned: imaginary part of complex number private: double real_part; double imag_part; };

complex_number operator + (const complex_number& c1, const complex_number& c2); // returned: sum of c1 and c2

complex_number operator - (const complex_number& c1, const complex_number& c2); // returned: difference of c1 and c2

complex_number operator * (const complex_number& c1, const complex_number& c2); // returned: product of c1 and c2

complex_number operator / (const complex_number& c1, const complex_number& c2); // precondition: c2 is not the zero of complex numbers // returned: quotient of c1 and c2

complex_number conjugate (const complex_number& c); // returned: conjugate of c

double complex_modulus (const complex_number& c); // returned: modulus of c

bool operator == (const complex_number& c1, const complex_number& c2); // returned whether c1 and c2 are equal to each other

bool operator != (const complex_number& c1, const complex_number& c2); // returned whether c1 and c2 are not equal to each other

std::ostream& operator

#endif // COMPLEX_NUMBER_H ------------------ TEST_COMPLEX.CPP #include #include #include #include #include "complex_number.h"

using namespace std;

int main() { complex_number c1(2.3, 4.8); assert (c1.get_real_part() == 2.3); assert (c1.get_imag_part() == 4.8);

complex_number c2 (2.6); assert (c2.get_real_part() == 2.6); assert (c2.get_imag_part() == 0.0); complex_number c3; assert (c3.get_real_part() == 0.0); assert (c3.get_imag_part() == 0.0);

assert (conjugate(c1).get_real_part() == 2.3); assert (conjugate(c1).get_imag_part() == -4.8);

assert (abs (complex_modulus (c1) - 5.322593353)

assert (c1 != c2);

complex_number c5 (1.3, -4.1);

complex_number c6 = c4 + c5; assert (abs (c6.get_real_part() - 3.6)

complex_number c7 = c4 - c5; assert (abs (c7.get_real_part() - 1.0)

complex_number c8 = c4 * c5; assert (abs (c8.get_real_part() - 22.67)

complex_number c9 = c4 / c5; assert (abs (c9.get_real_part() + 0.902162162)

cout

COMPLEX_NUMBER.CPP (this is the one that needs to be edited)

#include "complex_number.h"

complex_number::complex_number(double r = 0.0, double i = 0.0) { real_part = r; imag_part = i; }

double complex_number::get_real_part () const{

return real_part; } /************implement the remaining functions here *******/

The purpose of this lab is to reinforce the concept of constructing and testing a class in C++. Specifically, the problem is to do problem 19 on page 95 of the text. Use the header file complex_number.h, complex_number.cpp and the test program test_complex.cpp provided for this lab. You will need to implement all the functions defined in the complex_number.h file in the implementation file. You do not need to make any changes to the test file. Remember that the your code must compile and run correctly on the cloudland server

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!