Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

2) (10 points) Given the following definition of the class Circle that represent

ID: 3903235 • Letter: 2

Question

2) (10 points) Given the following definition of the class Circle that represents a circle of radius r and the position (x.y) of its center in the x-y plane, write the implementation of a member function overlaps that takes a const Circles argument and returns true if the calling Circle overlaps with the Circle passed as an argument (and returns false if there is no overlap). If one circle lies entirely in another circle, the two circles overlap. If two circles touch at exactly one point, they do not overlap. class Circle public: Circle(int xva private: int x, Yr l, int yval, int rval) ; Answer

Explanation / Answer

#include <iostream>
#include <cmath>
using namespace std;

class Circle
{
private:
int x,y,r;

public:
Circle(int xval,int yval,int rval)
{
x = xval;
y = yval;
r = rval;
}

bool overlaps(const Circle &c)
{
//if the invoking object with this pointer contains the furtherest point from center , it overlaps Circle c
if(this->r >= sqrt((c.x-this->x)*(c.x-this->x)+(c.y-this->y)*(c.y-this->y))+c.r)
return true;
else
return false;
}

};
int main() {

Circle c1(5,5,6);

Circle c2(3,4,5);

if(c1.overlaps(c2))
cout<<"Circle c1 overlaps circle c2";
else
cout<<"Circle c1 does not overlap circle c2";
return 0;
}

output:

Circle c1 does not overlap circle c2

Do ask if any doubt. Please upvote.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote