Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Programming questions

Question

Explain about Data Structures in Detail and explain about arrays?

Answered: 1 week ago

Question

Explain about operations on Data Structure?

Answered: 1 week ago