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.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>
#include <cmath>

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...
i want to ask..
how to create a calculator programe..
please help me.. urgent..
:(
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.

1
2
3
4
bool containsPoint(double xValue, double yValue)
{
 // ...
}

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

1
2
3
4
5
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.