CS2028 Lab 3- Classes, multi-file programs and operator overloading Solved

30.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: zip solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

5/5 - (3 votes)

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.
    1. 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).
    2. Make all attributes (variables) private.
    3. Declare getters and setters for all attributes as appropriate.
    4. 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.
    1. 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.
    2. 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.
    3. 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.
    1. Prompt the user for x and y values for the complex number.
    2. Prompt the user for the operation to perform.
    3. Prompt the user for the values for other class instance or scaler to be used in the calculation.
    4. Display the results.
    5. 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.
  • lab03-gauim4.zip