Question
In C++......This code prints the position of point P relative to a circle. (inside/outside/on circle). Complete the following code with the bold requirements. Do not
In C++......This code prints the position of point P relative to a circle. (inside/outside/on circle). Complete the following code with the bold requirements. Do not write anorher code. Just complete it.
#include
using namespace std;
struct Point{ float x; float y; };
class Circle{ private: struct Point center; float ray;
public: Circle(struct Point centerCoord, float valRay){ center = centerCoord; ray = valRay; }
float getRay(){ return ray; }
struct Point getCenter(){ return center; }
float getArea(){ return ray * ray * 3.14; }
int pointPosOnCircle(struct Point P){ float distance = sqrt((P.x - center.x) * (P.x - center.x) + (P.y - center.y) * (P.y - center.y)); if (distance > ray) { return 1; // point is outside the circle } else if (distance < ray) { return -1; // point is inside the circle } else { return 0; // point is on the circle } } };
int main(){ struct Point C, P; float r;
cout << "Enter center coordinates of circle: "; cin >> C.x >> C.y;
cout << "Enter radius of circle: "; cin >> r;
Circle obCircle(C, r);
cout << "Radius of circle is " << obCircle.getRay() << " and area is " << obCircle.getArea() << endl; cout << "Coordinates of center of the circle are: O(" << obCircle.getCenter().x << ", " << obCircle.getCenter().y << ")" << endl;
cout << "Enter coordinates of a point to check if it is inside, outside, or on the circle: "; cin >> P.x >> P.y;
int pointPos = obCircle.pointPosOnCircle(P);
if (pointPos == 1) { cout << "Point is outside the circle." << endl; } else if (pointPos == -1) { cout << "Point is inside the circle." << endl; } else { cout << "Point is on the circle." << endl; }
TO DO:
Shift the center of the circle in point P
system("pause"); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started