I am trying to write a function that checks if a given point is included in a circle (located in the integers xy plane). For that task, I want to use classes, which I wrote as shown below.
class Point
{
public:
Point(int x, int y);
int getX() const;
int getY() const;
void setX(int x);
void setY(int y);
private:
int x, y;
};
class Circle
{
public:
Circle(int x, int y, int r);
bool contains(const Point &p) const;
private:
const Point center;
int radius;
};
I find some difficulty in writing the function 'contains'. Here is what I have done. When I wrote this function, I got an error that says that "member Point::x is inaccessible", and I cannot understand what is wrong.
bool Circle::contains(const Point &p) const
{
if ((p.x-center.x)>=(-1*radius) && (p.x-center.x)<=radius && (p.y-center.y)>=(-1*radius) && (p.y-center.y)<=radius )
return true;
return false;
}