Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

[5 pts) 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 (_e ) and Full Section 3.3.8. Emulating numeric types in [5 pts) 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 (_e ) and Full Section 3.3.8. Emulating numeric types in

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

OCA Oracle Database SQL Exam Guide Exam 1Z0-071

Authors: Steve O'Hearn

1st Edition

1259585492, 978-1259585494

Students also viewed these Databases questions