Question: Please Program in C++ 2) Complex Class A complex number is of the form a + bi where a and b are real numbers and

Please Program in C++

2) Complex Class

A complex number is of the form a + bi where a and b are real numbers and i 2 = -1.

For ex- ample, 2.4 + 5.2i and 5.73 - 6.9i are complex numbers. Here, a is called the real part of the complex number and bi the imaginary part.

In this part you will create a class named Complex to represent complex numbers. (Some lan- guages, including C++, have a complex number library; in this problem, however, you write the complex class yourself.) The members of this class are as follows: Private data members: real and imag of type double - to represent the complex number (real + imag i) Public member functions: Default constructor that will initialize real and imag to zero void input(istream&); //Input values from the specified stream for real and imag void output(ostream&); // Output the Complex number to the specified stream in this form e.g.,: 2.3 + 4.6i double getReal(); // Accessor method that returns the value of data member real double getImag(); //Accessor method that returns the value of data member imag void setReal(double); // Mutator method that sets the value of real void setImag(double); // Mutator method that sets the value of imag Before writing any code, you and your partner should discuss what the code for this class will look like. Make sure you both have a good idea of what you need to do before you start writing code for this class.

Write a main() driver function that calls the appropriate member functions to do the following:

Declare two Complex objects: c1 and c2.

Prompt the user and use the input method to input complex values for the two objects c1 and c2.

Display c1 and c2 using the output method.

Use setReal() to change the value of real for object c2 to 22.2. 3

Use getReal() to obtain the value of real for object c2; display the value on the terminal screen.

Display the updated c2 value using the output() method.

Example (user input is underlined): Enter values for real and imaginary coe icients: 17.4 3.9 Enter values for real and imaginary coe icients: 10.2 16.81 17.4 + 3.9i 10.2 + 16.8i Enter a new value for the real coe icient: 22.2 The new real coe icient is 22.2 22.2 + 16.8i

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!