Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Base on the code assignment below. I need help answering ONLY question 7 and 9.

ID: 3752263 • Letter: B

Question

Base on the code assignment below. I need help answering ONLY question 7 and 9. Thank you.

Problem: Create a Complex class inside Complex.h file. Each complex number has an imaginary and a real part. The only constructor of this class should receive two integers as input. A Complex object should not have any setters but should have getters. Create a print function for your Complex class. Create a non-member function complex_add for your Complex class, that receives two Complex objects, add them together and returns a Complex object that is the result of the addition. Create complex_sub that does the subtraction. Inside your main receive two integers from the user and create a Complex number out of that; do the same thing to generate the second Complex number. Check to see if these two complex numbers are equal or not? Print the result of addition and subtraction of these two complex number to the user

Explanation / Answer

7. add and subtract are better to be non-member functions because they can simply take in two Complex Structures and return another Complex Structure. There is no need of manipulating the original variables. However, shift actually changes the value of the complex number in question itself. Good Encapsulation and Abstraction practises require that shift be a member function.

9. Since add and subtract are non member function, it is better to name them with the prefix complex. In that way they are easier to distinguish from any other functions that we might create, maybe for some other type of structure. With names like complex_add and complex_shift the intention of the function is clear to the user. However, shift is a member function, so by default it will work only on an object of type complex thus, there is no need to specifying explicitly.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote