1 Modify the current operations so that it is impossible for
Solution
//below method sets the value of x to possitive irrespective of the value passed.
bool NewPoint::setX(int ux)
{
x=abs(ux); //abs changes negative number to possitive
return true;
}
//below method sets the value of y to possitive irrespective of the value passed.
bool NewPoint::setY(int uy)
{
y=abs(uy);
return true;
}
//below method sets the both value of x and value of y to possitive irrespective of the values passed.
bool NewPoint::set(int ux,int uy)
{
x=abs(ux);
y=abs(uy);
return true;
}
//caluclating distance between two points p and q.
double NewPoint::distance(NewPoint p,NewPoint q)
{
double dist;
dist=sqrt((p.x-q.x)*(p.x-q.x)+(p.x-q.x)*(p.x-q.x));
return dist;
}
//reflecting along the x axis will change only y coordinate to negative
void newPoint::reflect_alongx(NewPoint p)
{
p.y=-p.y;
}
//reflecting along the x axis will change only x coordinate to negative
void newPoint::reflect_alongy(NewPoint p)
{
p.x=-p.x;
}
