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: 3903208 • 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 xval, int yval, int rval); private: int x, Yr Answer:

Explanation / Answer

here is your class : ---------->>>>>>>>>>

#include<iostream>
#include<cmath>

using namespace std;

class Circle{
public:
  Circle(int xval,int yval,int rval){
   x = xval;
   y = yval;
   r = rval;
  }
  bool isInside(int x1, int y1)const{
      // Compare radius of circle with distance
      // of its center from given point
      if ((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y) <= r * r)
          return true;
      else
          return false;
  }

  bool overlaps(const Circle &cir){
   if(r < cir.r){
    for(int i = 0;i<360;i++){
     if(cir.isInside((r)*sin(i*(3.144/180)),(r)*cos(i*(3.144/180)))){
      
     }else{
      return false;
     }
    }
    
    return true;
   }else{
    for(int i = 0;i<360;i++){
     if(isInside((cir.r)*sin(i*(3.144/180)),(cir.r)*cos(i*(3.144/180)))){
      
     }else{
      return false;
     }
    }
    
    return true;
   }
  }
  
private:
  int x,y,r;
};


int main(){
Circle c1(0,0,4),c2(0,2,6);
if(c2.overlaps(c1)){
  cout<<"yes";
}
}

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