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:
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
C++
Please help me. If possible can the code be as simple as possible please? so i can understand.

Transcribed Image Text:Classes and operator overloading
Define a class for complex numbers. A complex number is a number of the
form:
a + b*i where
for
purposes,
and b are numbers
of type
our
a
double
and i is a number that represents the quantity v-1 (i * i = -1).
Represent
a complex number
two
values
of
type double.
Name
the
as
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:
(а + b*i)-(с+d*i) %3
(а-с)+ (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 Cl and C2.
Add, subtract and multiply C3 and C4.
Use the overloaded « to display the result of the three operations
as follow:

Transcribed Image Text:7*i)
7*i)
|(1 + 4*i) + (-3
|(1 + 4*i)
|(1 + 4*i) * (-3 - 7*i)
(4*i) + (-3 + i)
(4*i)
|(4*i)
-2
3*i
%3D
(-3
4 + 11*i
-
%3D
25
19*i
-3 + 5*i
%3D
(-3 + i)
(-3 + i)
3 + 3*i
=
-4
12*i
%3D
||
||
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

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education