Home » C++ Programming » Functions » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    class ThreeDExample
    {
    int P, Q, R;
    public:
    ThreeDExample() { P = Q = R = 0; }
    ThreeDExample(int m, int n, int o) { P = m; Q = n; R = o; }
    ThreeDExample operator()(ThreeDExample obj);
    ThreeDExample operator()(int num0, int num1, int num2);
    friend ostream &operator<<(ostream &strm, ThreeDExample op);
    };
    ThreeDExample ThreeDExample::operator()(ThreeDExample object)
    {
    ThreeDExample temp;
    temp.P = (P + object.P) / 2;
    temp.Q = (Q + object.Q) / 2;
    temp.R = (R + object.R) / 2;
    return temp;
    }
    ThreeDExample ThreeDExample::operator()(int num0, int num1, int num2)
    {
    ThreeDExample temp;
    temp.P = P + num0;
    temp.Q = Q + num1;
    temp.R = R + num2;
    return temp;
    }
    ostream &operator<<(ostream &strm, ThreeDExample obj) {
    strm << obj.P << ", " << obj.Q << ", " << obj.R << endl;
    return strm;
    }
    int main()
    {
    ThreeDExample objectA(1, 2, 3), objectB(10, 10, 10), objectC;
    objectC = objectA(objectB(50, 150, 250));
    cout << objectC;
    return 0;
    }
    1. 30, 81, 131
    2. 81, 131, 30
    3. 131, 81, 30
    4. 81, 30, 131
    5. None of these
Correct Option: A

In this program, We are using the function call operator to calculate the value of objectC.



Your comments will be displayed only after manual approval.