Question: Two complex numbers are equal if and only if the real parts are equal and the imaginary parts are equal. For example, 3 + 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 ([])
The code for the Complex class should be saved in the complexNumbers.py file.
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:
-
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
- 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:
- 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.
- 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.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
