Question: Please write this C++ program as requested in the prompt below using problem 19 and the header files and test program included below (Complex_number.h) (Complex_number.cpp)
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. Write a class for complex numbers. A com plex number has the form a + bi, where a and b are real numbers and i is the square root of -1. We refer to a as the real part and b as the imaginary part of the number. The class should have two data members to represent the real and imaginary numbers; the constructor takes two ar guments to set these members. Discuss and imple- ment other appropriate operators for this class. 1 ifndef COMPLEX NUMBER H 2 tdefine COMPLEX NUMBER H 4 class complex number 6 public: 7 complex number (double r 0.0, double i 0.0) 8 postcondition: complex with given components has been created 9 double get real part 0 const 10 // returned: real part of complex number 11 double get_imag_part ) const 12 returned: imaginary part of complex number 13 private: 14 double real part: 15 double imag part: 16 1 17 18 19 complex_number operator (const complex numbers c1, const complex_numbers c2) 20 // returned: sum of cl and c2 21 22 complex_number operator (const complex number c1, const complex number& c2) 23// returned: difference of cl and c2 24 25 complex_number operator (const complex numbere ci, const complex number c2): 26// returned: product of ci and c2 27 28 complex number operator / (const complex_number cl, const complex_ number c2): 29 // precondition: c2 is not the zero of complex numbers 30// returned: quotient of cl and c2 31 32 complex number conjugate (const complex_ number& c) 33/ returned: conjugate of c 34 34 35 double complex modulus (const complex-number& c); 36 // returned: modulus of c 37 38 bool operator (const complex number& c1, const complex number& c2) 39// returned whether cl and c2 are equal to each other 40 1 bool operator-(const complex_number& c1, const complex_number&c2) 42 // returned whether cl and c2 are not equal to each other 43 44 std: :ostream& operator
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
