Question: Implement a C++ class Complex' to store complex numbers. A complex number is a number that is formed of a real and of an imaginary

Implement a C++ class "Complex' to store complex numbers. A complex number is a number that is formed of a real and of an imaginary part. It can be expressed as: a + bi where a is the real number, and b is the imaginary unit. For example: 2 + 3i.

More precisely, your class should contain:

1. Data members: double real double imaginary.

2. A constructor that takes the real and imaginary parts.

3. A default constructor that initializes both data items to O.

Then you need to implement the following:

1. Overload the output operator («) to display any complex number as: real + imaginary I. Notice that if the imaginary number is negative, the number should be displayed as: real -Imaginary i.

2. Overload the input operator (») to take a complex number as input as follows: real + imaginary i (or real - imaginary i).

3. Overload the corresponding operator, to allow the addition of two complex numbers. To add two complex numbers, the real numbers will be added together and the imaginary ones will be added together. For example:

C1 = 12 - 34i

C2 = 10 + 40i

C3 =C1 +C2 =22 +6i

In the main function:

(a) Take two complex numbers as input from the user.

(b) Display the two numbers C1 and C2 (using cout «)

(c) Create a complex number C3 that is equal to C1 + C2

(d) Display C3 as follows:

C1 = 12 - 34i

C2 = 10 + 40i

C3 = C1 + C2 = 22 + 6i

Step by Step Solution

3.40 Rating (144 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Lets implement the required Complex class step by step in C to handle complex numbers Step 1 Define ... View full answer

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 Programming Questions!