Question: Please do in Python and nothing else!!!! (Math: The Complex class) Python has the complex class for performing complex number arithmetic. In this exercise, you

Please do in Python and nothing else!!!! (Math: The Complex class) Python has the complex class for performing complex number arithmetic. In this exercise, you will design and implement your own Complex class. Note that the complex class in Python is named in lowercase, but our custom Complex class is named with C in uppercase. A complex number is a number of the form where a and b are real numbers and i is The numbers a and b are known as the real part and the imaginary part of the complex number, respectively. You can perform addition, subtraction, multiplication, and division for complex numbers using the following formulas:

(a + bi) + (c + di) = (a + c) + (b + d)i

a + bi - (c + di) = (a - c) + (b - d)i

(a + bi)*(c + di) = (ac - bd) + (bc + ad)i

(a + bi)/(c + di) = (ac + bd )/(c2 + d2 ) + (bc - ad )i/(c2 + d2 )

You can also obtain the absolute value for a complex number using the following formula:

|a + bi| = sqrt(2a2 + b)

Design a class named Complex for representing complex numbers and the methods _ _add_ _, _ _sub_ _, _ _mul_ _, _ _truediv_ _, and _ _abs_ _ for performing complex-number operations, and override the _ _str_ _ method by returning a string representation for a complex number. The _ _str_ _ method returns (a + bi) as a string. If b is 0, it simply returns a. Provide a constructor Complex(a, b) to create a complex number with the default value of 0 for a and b. Also provide the getRealPart() and getImaginaryPart() methods for returning the real and imaginary parts of the complex number, respectively. Write a test program that prompts the user to enter two complex numbers and displays the result of their addition, subtraction, multiplication, and division. Here is a sample run:

Enter the first complex number:

Enter the second complex number:

(3.5 + 6.5i) + (-3.5 + 1i) = (0.0 + 7.5i)

(3.5 + 6.5i) - (-3.5 + 1i) = (7.0 + 5.5i)

(3.5 + 6.5i) * (-3.5 + 1i) = (-18.75 - 19.25i)

(3.5 + 6.5i) / (-3.5 + 1i) = (-0.43396226415 - 1.98113207547i)

|(3.5 + 6.5i)| = 4.47213595499958

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 Databases Questions!