help with class program

Need help with my containsPoint function. Do not know why I can not use my x, y and radius in my function.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091`` ``````#include #include using namespace std; class Circle { private: double x; double y; double radius; public: void setRadius(double); void setX(double); void setY(double); double getRadius(); double getX(); double getY(); double getArea(); bool containsPoint(double, double); }; void Circle::setRadius(double r) { radius = r; } void Circle::setX(double xCord) { x = xCord; } void Circle::setY(double yCord) { y = yCord; } double Circle::getRadius() { return radius; } double Circle::getX() { return x; } double Circle::getY() { return y; } double Circle::getArea() { return 3.14*radius*radius; } bool containsPoint(double xValue, double yValue) { bool status; double d; d = sqrt(pow((xValue - x), 2.0) + pow((yValue - y), 2.0)); if (d <= radius) status true; else status false; return status; } int main() { Circle c; double circX; double circY; double circRadius; double ptX; double ptY; cout << "Enter the x coordinate of the center of your circle"; cin >> circX; cout << "Enter the y coordinate of the center of your circle"; cin >> circY; cout << "Enter the radius of your circle"; cin >> circRadius; cout << "Enter a x coordinate"; cin >> ptX; cout << "Enter a y coordinate"; cin >> ptY; c.setX(circX); c.setY(circY); c.setRadius(circRadius); cout << "The area of your circle is: " << c.getArea() << endl; if (c.containsPoint(ptX, ptY)) cout << "c contains the the point" << endl; }``````
For line 53, it should be `bool Circle::containsPoint(double xValue, double yValue)`.

Another small mistakes at line 59 and line 61, it should be `status = true;` and `status = false;`
bool Circle:: containsPoint(double xValue, double yValue)
{
// etc
}

Last edited on
Sorry to hijack a little bit, but because Circle:: wasn't there, the function constainsPoint isn't accessing the class right? Or rather, isn't within scope.
Last edited on
sorry out of topic...
how to create a calculator programe..
:(
Wow, carless mistake I have made. Thank you guys for pointing it out.
 Sorry to hijack a little bit, but because Circle:: wasn't there, the function constainsPoint isn't accessing the class right? Or rather, isn't within scope.

Yes, that's correct.

 ``1234`` ``````bool containsPoint(double xValue, double yValue) { // ... }``````

defines a global function, that's not part of any class.

 ``12345`` ``````bool Circle::containsPoint(double xValue, double yValue) { // ... } ``````
defines a method of the class Circle.

Last edited on
Oh finally now I know what a method is, thanks Mikey.
Topic archived. No new replies allowed.