Description
The objective of this Lab is to create a class including constructors, using correct class file separation and implement operator overloading.
Task 1:Â Design Class (.h file)
- Create a new project. You can name this whatever you like.
- Design a class to allow calculations on complex numbers (numbers with a real and an imaginary component). A refresher can be found at https://en.wikipedia.org/wiki/Complex_number.
- Declare a default constructor and an overload of a constructor that supports passing each of the attributes in Cartesian complex plane form and polar complex plane form (total of 3 constructor versions).
- Make all attributes (variables) private.
- Declare getters and setters for all attributes as appropriate.
- Declare a print member function to print out the value using cout.
- Include in the submission your rationale for all members you have in your class.
Task 2:Â Implement the Class
- Write the implementation code for the methods declared in Task 1. The definitions should be in a separate .cpp file.
- Include in the lab report any changes you needed to make to the class declaration (.h file).
Task 3:Â Extend the class.
- Modify the class declaration and definition to overload the +, -, *, / and == operators to correctly perform those calculations.
- The + and – operators should accept an input parameter of the same class type and return void. This operation should update the contents of that instance.
- The * and / operators should accept an input parameter of the same type as the private variables holding the x and y values. This will be a scaler multiplication/division.
- The == operator should accept an input parameter of the same class type and return a bool indicating if the value is equivalent.
- Modify the class declaration and definition to include a member function returning the r and another returning the angle of the value phi (φ) in polar complex plane.
- Include in the lab report any changes you needed to make to the class declaration beyond the new functions being defined in this task
Task 4:Â Test the class.
- Create a program that tests the class.
- Prompt the user for x and y values for the complex number.
- Prompt the user for the operation to perform.
- Prompt the user for the values for other class instance or scaler to be used in the calculation.
- Display the results.
- Ask the user if they wish to continue. If so, loop to step b.
- Use your test program to test all member functions and ensure the class is working correctly.
- Include in the lab report a screen shot(s) of the output of a test of all operator overload functions.