Consider the Complex class with add member function and operator overloading for
ID: 3866179 • Letter: C
Question
Consider the Complex class with add member function and operator overloading for the + operator. Assume x and y are declared as Complex objects. Answer the following questions //first function Complex Complex: : add(const Complex 6c) const t Complex temp: temp.real - real + c.real: temp.imag = imag + c.imag: return tamp: }//second function Complex operators (const Complex 6c) { return this- > add(c): } Write an expression, using the first function, that adds x and y. Write an expression, using the second function, that adds x and y. Write an expression that uses the operator to add x and y Write a non member function to add two Complex objects.Explanation / Answer
5.a using first function
x and y are objects of type Complex
Complex d = x.add(y);
5.b
Complex d = x+y;
5.c
the ques is not clear which operator to be used
5.d
friend Complex operator+(Complex x, Complex y) {
Complex d ;
d.real = x.real + y.real;
d.imag = x.imag + y.imag;
return d;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.