Given the following composite data type in a statically-typed language: struct…

TS-SET (TG-SET) 2024

Given the following composite data type in a statically-typed language: struct Complex { double real; double imag; } If you were to extend this type to support addition of two Complex numbers, which operator overloading method would be most appropriate?

  1. A.

    Define a global function for adding two Complex numbers.

  2. B.

    Overload the “ ++ “ operator within the Complex struct definition.

  3. C.

    Use inheritance to create a subclass that supports addition.

  4. D.

    Implement a template function for adding Complex numbers.

Attempted by 6 students.

Sign up free to check your answer

Sign up free

Explore the full course: Uppsc Polytechnic Lecturer 2025 Cs

Loading lesson…