C++ Program To Find Negation Of A Number | C++ Programming

C++ Program To Find Negation Of A Number

#include <iostream>
using namespace std;
class point
{
    int x, y;

public:
    void getdata()
    {
        cout << "Enter x and y coordinate:";
        cin >> x >> y;
    }
    void display()
    {
        cout << "(" << x << "," << y << ")";
    }
    point operator-()
    {
        point t;
        t.x = -x;
        t.y = -y;
        return t;
    }
};
int main()
{
    point p, q;
    p.getdata();
    q = -p;
    cout << "q=";
    q.display();
}

OUTPUT


Enter x and y coordinate:
5
4
q=(-5,-4)

Comments

Popular posts from this blog

C Program for SCAN Disk Scheduling Algorithm | C Programming

C program to Find Cartesian Product of Two Sets | C programming

C Program To Check The String Is Valid Identifier Or Not | C Programming