Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the class Complex that supports the basic complex number operations. Such operations are addition (+), subtraction (-), multiplication (*) and division (/) of complex

Write the class Complex that supports the basic complex number operations. Such operations are addition (+), subtraction (-), multiplication (*) and division (/) of complex numbers, and addition (+), subtraction (-) and multiplication (*) of a complex by a scalar (float or int). All methods must return (not print) the result. Class also supports the rich comparison for equality (= =)

- Check the doctest for object behavior examples.

- You must use the special methods for those 5 operators in order to override their behavior.

- You will need other special methods to achieve a legible object representation (what you see when printing and returning the object).

- Addition, subtraction and multiplication by scalar and by another complex number use the same operator, so you must check the type of the object in order to decide which operation you have to perform

- Rich comparison returns a Boolean value

- The rest of the methods must return a new Complex object, this means the original objects should not change after the operation is performed.

- Test your code, this is how you ensure you get the most credit out of your work!!

- When performing an invalid operation, return None

- You are not allowed to modify the constructor or any given code.

- Note that to support number (+, - or *) Complex, you are going to need 3 other special methods that can reuse code from the Complex (+, - or *) number operations. Hint: Section 3.3.1. Basic customization (__eq__) and Full Section 3.3.8.

In addition, write the property method conjugate into the Complex class. The complex conjugate of the complex number z = x + yi is given by x yi

Remember, you are not allowed to modify the given constructor. The method conjugate must be a property method, otherwise, no credit will be given. Property methods are discussed in the video lectures!

python

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

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions