Define a class for complex numbers. A complex number is a number of the form a + b*i where for our purposes, a and b are numbers of type double, and i is a number that represents the quantity √-1. Represent a complex number as two values of type double. Name the member variables real and imaginary. (The variable for the number that is multiplied by i is the one called imaginary.) Call the class Complex. Include a constructor with two parameters of type double that can be used to set the member variables of an object to any values. Include a constructor that has only a single parameter of type double; call this parameter realPart and define the constructor so that the object will be initialized to realPart + 0*i.Include a default constructor that initializes an object to 0 (that is, to 0 + 0*i).Overload all the following operators so that they correctly apply to the type Complex: ==, +, −, *, >>, and <<. You should also write a test program to test your class. Hints: To add or subtract two complex numbers, add or subtract the two member variables of type double. The product of two complex numbers is given by the following formula: (a + b*i)*(c + d*i) = = (a*c - b*d ) + (a*d + b*c)*iIn the interface file, you should define a constant i as follows:const Complex i(0, 1); This defined constant i will be the same as the i discussed above.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter11: Inheritance And Composition
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question

Define a class for complex numbers. A complex number is a number of the form a + b*i

where for our purposes, a and b are numbers of type double, and i is a number that represents the quantity -1. Represent a complex number as two values of type double. Name the member variables real and imaginary. (The variable for the number that is multiplied by i is the one called imaginary.) Call the class Complex. Include a constructor with two parameters of type double that can be used to set the member variables of an object to any values. Include a constructor that has only a single parameter of type double; call this parameter realPart and define the constructor so that the object will be initialized to realPart + 0*i.
Include a default constructor that initializes an object to 0 (that is, to 0 + 0*i).
Overload all the following operators so that they correctly apply to the type Complex: ==, +, −, *, >>, and <<. You should also write a test program to test your class. Hints: To add or subtract two complex numbers, add or subtract the two member variables of type double. The product of two complex numbers is given by the following formula:

(a + b*i)*(c + d*i) = = (a*c - b*d ) + (a*d + b*c)*i
In the interface file, you should define a constant i as follows:
const Complex i(0, 1); This defined constant i will be the same as the i discussed above. 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning