Question: 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
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 has the form
where
and
are real numbers and
is
The numbers
and
are known as the real part and imaginary part of the complex number, respectively. You can perform addition, subtraction, multiplication, and division for complex numbers using the following formulas:
You can also obtain the absolute value for a complex number using the following formula:
A complex number can be interpreted as a point on a plane by identifying the
values as the coordinates of the point. The absolute value of the complex number corresponds to the distance of the point to the origin
Write a class named Complex for representing complex numbers and the methods add, sub, mul, truediv, and abs for performing complexnumber 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 it simply returns a Provide a constructor Complexa b to create a complex number with the default value of for a and b Also provide the getRealPart and getImaginaryPart methods to get the real and imaginary parts of the complex number, respectively.
Sample Run
Enter the real part of the first complex number:
Enter the imaginary part of the first complex number:
Enter the real part of the second complex number:
Enter the imaginary part of the second complex number:
iii
iii
iii
iii
i
iiii
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
