ExamVeda
Login
Home
Classes and Objects in C plus plus
?


#include <iostream>
using namespace std;
class three_d 
{
    int x, y, z;
    public:
    three_d() { x = y = z = 0; }
    three_d(int i, int j, int k) { x = i; y = j; z = k; }
    three_d operator()(three_d obj);
    three_d operator()(int a, int b, int c);
    friend ostream &operator<<(ostream &strm, three_d op);
};
three_d three_d::operator()(three_d obj)
{
    three_d temp;
    temp.x = (x + obj.x) / 2;
    temp.y = (y + obj.y) / 2;
    temp.z = (z + obj.z) / 2;
    return temp;
}
three_d three_d::operator()(int a, int b, int c)
{
    three_d temp;
    temp.x = x + a;
    temp.y = y + b;
    temp.z = z + c;
    return temp;
}
    ostream &operator<<(ostream &strm, three_d op) {
    strm << op.x << ", " << op.y << ", " << op.z << endl;
    return strm;
}
int main()
{
    three_d objA(1, 2, 3), objB(10, 10, 10), objC;
    objC = objA(objB(100, 200, 300));
    cout << objC;
    return 0;
}

Answer & Solution
Correct Answer: Option A
Let's discuss the solution. Join the discussion
Examveda
Question posted by Examveda
Community

Join the Discussion

No comments yet Be the first to discuss this question.