Classes and operator overloading Define a class for complex numbers. A complex number is a number of the form: + b*i where for our purposes, and b numbers of type a a are double and i is a number that represents the quantity v-1 (i * i =-1). Represent complex number as two values of type double. Name the a member variables real and imaginary. (The variable for the number that is multiplied by i is the called imaginary.) Call the class one 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 constructor that has only a single parameter of type a 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: +, -, *, «, (>> optinal) The sum of The product of two complex numbers is given by the following formula: (a + b*i)+(c + d*i) = (a+c)+ (b+d) *i The difference of The product of two complex numbers is given by the following formula: (a + b*i)- (c + d*i) = (а-с) + (b-d) *i 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 You should also write a test program: Instantiate four complex numbers C1=(1+4*i), C2=(-3-7i), C3=(4*i) and C4= (-3+ i) Add, subtract and multiply C1 and C2. Add, subtract and multiply C3 and C4. Use the overloaded << to display the result of the three operations as follow:
Classes and operator overloading Define a class for complex numbers. A complex number is a number of the form: + b*i where for our purposes, and b numbers of type a a are double and i is a number that represents the quantity v-1 (i * i =-1). Represent complex number as two values of type double. Name the a member variables real and imaginary. (The variable for the number that is multiplied by i is the called imaginary.) Call the class one 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 constructor that has only a single parameter of type a 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: +, -, *, «, (>> optinal) The sum of The product of two complex numbers is given by the following formula: (a + b*i)+(c + d*i) = (a+c)+ (b+d) *i The difference of The product of two complex numbers is given by the following formula: (a + b*i)- (c + d*i) = (а-с) + (b-d) *i 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 You should also write a test program: Instantiate four complex numbers C1=(1+4*i), C2=(-3-7i), C3=(4*i) and C4= (-3+ i) Add, subtract and multiply C1 and C2. Add, subtract and multiply C3 and C4. Use the overloaded << to display the result of the three operations as follow:
Chapter7: Characters, Strings, And The Stringbuilder
Section: Chapter Questions
Problem 18RQ
Related questions
Question
C++
Please help me. If possible can the code be as simple as possible please? so i can understand.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
Knowledge Booster
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.Recommended textbooks for you
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning