State the Output Unary Operator Overloading 2

/*
    State the Output
*/
#include<iostream>
using namespace std;

class 3D
{
    int x,y,z;

    public:
            3D(int a=0,int b=0,int c=0)
            {
                x=a;
                y=b;
                z=c;
            }

            3D operator ++()
            {
                x=x+1;
                y=y+1;
                z=z+1;
                return *this;
            }

            3D operator ++(int)
            {
                3D t=*this;
                x=x+1;
                y=y+1;
                z=z+1;
                return t;
            }

            3D show()
            {
                cout<<"\n\n The elements are:";
                cout<<" x: "<<this->x<<", y:"<<this->y<<", z:"<<this->z;
            }
};

int main()
{
    3D pt1(2,4,5),pt2(7,1,3);

    cout<<" Points one's dimensions before increment are: "<<pt1.show();
    ++pt1;

    cout<<" Points one's dimensions after increment are: "<<pt1.show();

    cout<<" Points two's dimensions before increment are: "<<pt2.show();
    pt2++;

    cout<<" Points two's dimensions after increment are: "<<pt1.show();

    return 0;
}

Previous
Next Post »