Arithmetic operations on two complex numbers (a, b) and (c,
d) are as follows:
(a, b) + (c, d) = (a + c, b + d)
(a, b) - (c, d) = (a - c, b - d)
Multiplication: (a, b) *
(c, d) = (a * c - b * d, a * d + b * c)
(a, b) / (c, d) = ((a * c + b * d)/(c2 + d2), (b * c - a
* d)/(c2 + d2))
Absolute value: |(a, b)|
= sqrt(a2 + b2)
Design and implement a ComplexNumber class that represents the real and imaginary parts as double
values and provides at least the following methods:
- Constructors for default and explicit initialization.
method to read a complex
number. Look at the sample output screen for the design required.
method to print a complex
number as (a, b). Have 2 decimals for both.
method called getReal
that returns the real part of a complex number.
method called getImaginary
that returns the imaginary part of a complex number.
equal, copy, getCopy,
methods to add, subtract, multiply, and divide
two complex numbers.
method called cAbs to implement the
absolute value of a complex number.
To test your class write a client
that has at least a function menu()
with options for the methods implemented and an option to exit. Your program
should loop until the user chooses to exit. In this loop you are required to
use a switch statement for all
this is class obj methods.... so use class obj method.