Write a class to represent a complex number of the form a + bi, where i is the imaginary square root of 1. The constructor should accept two doubles as arguments: the real part a and the imaginary...


Write a class to represent a complex number of the form a + bi, where i is the imaginary square root of 1. The constructor should accept two doubles as arguments: the real part a and the imaginary part b. Use an assertion in the constructor to ensure that both of these numbers are positive. The methods you must provide are summarized in Figure 1–32. You may want to include others, such as a main() method for testing. One good test is to create the number 3 + 4i and print its magnitude:




This should print 5.0. Hint: The built-in Math class contains static methods sqrt() (to find a square root) and atan() (to find an arctangent).


Figure 1–32



Nov 29, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here