Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python plz Define a class Complex to represent complex numbers. All complex numbers are of the form x + yi, where x and y are

image text in transcribed

image text in transcribed

image text in transcribed

Python plz

Define a class Complex to represent complex numbers. All complex numbers are of the form x + yi, where x and y are real numbers, real numbers being all those numbers which are positive, negative, or zero. In general, the x part of a complex number x + yi is called the real part, while y is called the imaginary part. To add or subtract two complex numbers, you just add or subtract the corresponding real and imaginary parts. For instance, the sum of 5 + 3i and 4 + 2i is 9 + 5i. And the result of 3 + 4i minus 1 + 2i is 2 + 2i. Two complex numbers are equal if and only if the real parts are equal and the imaginary parts are equal. For example, 3 + 2i and 3 + 2i are equal, but 3 + 2i and 3 + 4i are not equal. Start by defining a class to represent complex numbers. Provide a constructor, mutators (for both attributes), and inspectors (for both attributes. Assume that if not data is provided, both the real and imaginary parts of a complex number are both equal to zero. Then proceed to overload the following operators: The print operator. A complex number such as 3 + 4i will be displayed as follows: (3 + 4i) The addition (+) and subtraction (-)operators. The comparison operators for equality (--) and inequality (! =) The subscript operator (I) In the main.py file you will have the main script for this assignment. Here are some additional specifications: Your program should present a menu to the user with the following options: o 1. Add a complex number to the collection o 2. Print collection o 3. Add all complex numbers in the collection o 4. Search for a complex number o 5. Exit Option 1 allows the user to create complex numbers to be added to a list. The program should ask the user to enter the real and imaginary parts of a complex number, create a Complex object and add it to a list of complex objects. Option 2 prints the entire list of complex numbers. Option 3 adds all the complex numbers stored in the list and display the result. Option 4 allows the user to search for a complex number to see if it is in the list. Start by asking the user to enter the complex number then display whether the number is in the list or not. If the number is in the list display the index where the number is located. Option 5 allows the user to exit the program. Your program must have the following functions: o validateInteger(): the purpose of this function is to validate a value entered by the user to make sure the value is an integer. This function takes no parameters and it returns an integer value entered by the user. o search(numberList, searchvalue): this function implements linear search. The function receives a list of complex numbers, a complex number to be searched. The function returns the location of the complex number if found in the list, or -1 if not found. Enter the real part: 5 Enter the imaginary part: 7 1. Add a complex number to the collection 2. Print collection 3. Add all complex numbers in the collection 4. Search for a complex number 5. Exit Enter your choice: 2 (1 + li) (2 + 3i) (5 + 7i) 1. Add a complex number to the collection 2. Print collection 3. Add all complex numbers in the collection 4. Search for a complex number 5. Exit Enter your choice: 3 The result is: (8 + 11i)

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

Pro Oracle Fusion Applications Installation And Administration

Authors: Tushar Thakker

1st Edition

1484209834, 9781484209837

More Books

Students also viewed these Databases questions