Thursday, 15 August 2013

UNARY operetor in C++

#include<iostream.h>
#include<conio.h>

class data
{
    int x,y;
    public:
        void get()
        {
             cout<<"enter x";
            cin>>x;
             cout<<"enter y";
            cin>>y;


        }

        void operator -()
        {
            x=-x;
            y=-y;
        }

        void disp()
        {
            cout<<"\n x="<<x;
            cout<<"\n y="<<y;
        }
};
void main()
{
    data d;

    clrscr();

    d.get();
    -d;

    d.disp();

    getch();
}

No comments:

Post a Comment