Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #include #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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Filing And Computer Database Projects

Authors: Jeffrey Stewart

2nd Edition

007822781X, 9780078227813

More Books

Students also viewed these Databases questions