Design (pseudocode) and implement (source code) a program (name it Circles) to d
ID: 3748424 • Letter: D
Question
Design (pseudocode) and implement (source code) a program (name it Circles) to determine if a circle is either completely inside, overlapping with, or completely outside another circler. The program asks the user to enter the center point (X1, Y1) and the radius (R1) for the first circle C1, and the center point (X2, Y2) and the radius (R2) for the second circle C2. The program then determines if the second circle C2 is either completely inside, or overlapping with, or completely outside the first circle C1. Hint: use the sum of R1 and R2 and the distance between the centers to solve the problem. Document your code, properly label the input prompts, and organize the outputs as shown in the following sample runs.
Sample run 1:
Circle 1 center is: (0,0)
Circle 1 radius is: 6
Circle 2 center is: (1,1)
Circle 2 radius is: 1
Judgment: Circle 2 is completely inside circle 1
Explanation / Answer
//Here is C++ Code
#include<iostream>
#include<math.h>
using namespace std;
int main(){
float x1,y1; //Center of circle 1 (x1,y1)
float x2,y2; //Center of circle 2 (x2,y2)
float r1,r2; //Radii of circles r1 and r2
float d; //Distance between centers of circles
cout<<"Enter co - ordinates of center (x1,y1) and radius r1 of circle 1 : ";
cout<<" x1 : ";
cin>>x1;
cout<<"y1 : ";
cin>>y1;
cout<<"r1 : ";
cin>>r1;
cout<<"Enter co - ordinates of center (x2,y2) and radius r2 of circle 2 : ";
cout<<" x2 : ";
cin>>x2;
cout<<"y2 : ";
cin>>y2;
cout<<"r2 : ";
cin>>r2;
d = sqrt(pow((x2-x1),2) + (y2-y1)*(y2-y1));
if(d>(r1+r2)){
cout<<"One circle is completely outside another circle.";
}else if(d<=(r1+r2) && d>abs(r1-r2)){
cout<<"Circles are overlapping.";
}else{
cout<<"One circle is inside another circle.";
}
return 0;
}