1 Modify the current operations so that it is impossible for

1. Modify the current operations so that it is impossible for a user to set the point to a negative x or a negative y value. 2. Add a new operation that would compute and return the distance from another point (implement line 20 in the posted code) 3. Add a new reflect operation that would reflect a point across both x and y axes (google \"Reflecting points in the coordinate plane\") Demonstrate that the upgraded NewPoint works in the main function.

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;
}

 1. Modify the current operations so that it is impossible for a user to set the point to a negative x or a negative y value. 2. Add a new operation that would

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site