Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

include include using namespace std class Complex public Complexdouble r 00 double i 00 constructor ... 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_2

Step: 3

blur-text-image_3

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

Numerical Methods For Engineers

Authors: Steven C. Chapra, Raymond P. Canale

5th Edition

978-0071244299, 0071244298

More Books

Students also viewed these Programming questions

Question

Solve each equation or inequality. |6x8-4 = 0

Answered: 1 week ago