-
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;
}
-
- 30, 81, 131
- 81, 131, 30
- 131, 81, 30
- 81, 30, 131
- None of these
Correct Option: A
In this program, We are using the function call operator to calculate the value of objectC.