Starting from:
$30

$24

Lab 3 Classes, multi-file programs and operator overloading Solution

Objective:

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




Lab Submission:

Write a lab report including the following information:

A description of the objectives/concepts explored in this assignment including why you think they are important to this course and a career in CS and/or Engineering.
Why you designed the class the way you did initially, what changes you made because of each task and what considerations you consider important when designing classes.
Include all source code from all tasks, input and output files (if any), and any special instructions to compile and run those programs.
Mention the contribution of each group member explicitly.
Package all files in a single zip folder and submit the file to Canvas
TA: muppalsa@mail.uc.edu




Lab Grading:

20% - Lab attendance
5% - Task 1 has been correctly implemented and meets all requirements.
15% - Task 2 has been correctly implemented and meets all requirements.
30% - Task 3 has been correctly implemented and meets all requirements.
10% - Task 4 has been correctly implemented and meets all requirements.
20% - Lab report contains all required information and is well written.
If program fails to compile, 0% will be given for that Task.

More products