Starting from:

$30

CS2028-Lab 3 Classes, Multi-File Programs and Operator Overloading Solved

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)

1.     Create a new project.  You can name this whatever you like.

2.     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.

a.      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).

b.     Make all attributes (variables) private.

c.      Declare getters and setters for all attributes as appropriate.

d.     Declare a print member function to print out the value using cout.

3.     Include in the submission your rationale for all members you have in your class.

 

Task 2:  Implement the Class

1.     Write the implementation code for the methods declared in Task 1.  The definitions should be in a separate .cpp file.

2.     Include in the lab report any changes you needed to make to the class declaration (.h file).

 

Task 3:  Extend the class.

1.     Modify the class declaration and definition to overload the +, -, *, / and == operators to correctly perform those calculations.

a.      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.

b.     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. 

c.      The == operator should accept an input parameter of the same class type and return a bool indicating if the value is equivalent.

2.     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.

3.     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.

1.     Create a program that tests the class.

a.      Prompt the user for x and y values for the complex number.

b.     Prompt the user for the operation to perform.

c.      Prompt the user for the values for other class instance or scaler to be used in the calculation.

d.     Display the results.

e.      Ask the user if they wish to continue.  If so, loop to step b.

2.     Use your test program to test all member functions and ensure the class is working correctly.

3.     Include in the lab report a screen shot(s) of the output of a test of all operator overload functions.

More products