Friday, 26 January 2018

Create a class SPACE having three member data x(int),y(int),z(int).overload the unary ‘-‘ operator for the class SPACE.

#include<iostream>
using namespace std;

class SPACE
{
    int x,y,z;
   
    public:
            SPACE()
            {
                x=10;
                y=11;
                z=12;
            }
            SPACE operator -()
            {
                SPACE ob;
                ob.x = -x;
                ob.y = -y;
                ob.z = -z;
               
                return ob;
            }
           
            void display()
            {
                cout<<"\nX is: "<<x<<"\nY is: "<<y<<"\nZ is: "<<z;
            }
};
int main()
{
    SPACE ob1,ob2;
    ob1.display();   
    ob2=-ob1;
    ob2.display();
    return 0;
}

No comments:

Post a Comment

It's time To increase blogging capability. To have a chance to contribute in digital world. Any Interested People who want to make t...