Question: A complex (imaginary) number has the form a + bi, where a is called the real part, b is called the imaginary part, andi=sqrt(-1). A

A complex ("imaginary") number has the form a + bi, where a is called the real part, b is called the imaginary part, andi=sqrt(-1). A complex number a + bi can be expressed as the ordered pair of real numbers (a, b).

Arithmetic operations on two complex numbers (a, b) and (c, d) are as follows:

Addition:(a, b) + (c, d) = (a + c, b + d)

Subtraction:(a, b) - (c, d) = (a - c, b - d)

Multiplication:(a, b) * (c, d) = (a * c - b * d, a * d + b * c)

Division:(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 aComplexNumberclassthat represents the real and imaginary parts as double values and providesat leastthe following methods:

  • Constructorsfor default and explicit initialization.
  • A method toread(get input) a complex number. Look at the sample output screen for the design required.
  • A method toprinta complex number as (a, b). Have 2 decimals for both.
  • A method calledgetRealthat returns the real part of a complex number.
  • A method calledgetImaginarythat returns the imaginary part of a complex number.
  • Methodsequals, copy,getCopy,toString.
  • Arithmetic methods toadd,subtract,multiply, anddividetwo complex numbers.
  • A method calledcAbsto implement the absolute value of a complex number.

To test your class write a client that hasat leasta functionmenu()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 aswitchstatement for all possible cases (similar design as the one used for Problem#1 in Assignment#1).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!