Search This Blog

Wednesday 24 February 2016

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

Practical 20


#include<iostream>
using namespace std;

class space
{
    int a,b,c;
    public:
    void setdata(int x,int y,int z)
    {
        a=x;
        b=y;
        c=z;
    }
    void display()
    {
        cout<< a <<" ";
        cout<< b <<" ";
        cout<< c <<endl;
    }
    void operator-();
};

void space::operator-()
{
    a=-a;
    b=-b;
    c=-c;
}

int main()
{
    space s;
    s.setdata(10,-20,73);
    cout<<"S : ";
    s.display();
    -s;
    cout<<"S : ";
    s.display();
    return 0;
}




output:

S:
10  -20  73

S:
-10  20  -73

No comments:

Post a Comment