5. Write a C++ program that prompts the user to enter the center coordinates and
ID: 3885995 • Letter: 5
Question
5. Write a C++ program that prompts the user to enter the center coordinates and radii of two circles and determines whether the second circle is inside the first, overlaps with the first or is total outside. Turn in output for the following circle tests: X1 Y1 R1 X2 Y2 R2 0 0 2 1 1 1 1 0 3 0 0 .5 -5 -5 5 -5 -1 2 4 -2 4 -4 4 1 _________________________________________________________________ Turn in a print out of the source code and screen shot of the output. Also, email me the source code and the .exe file. Use the following template for your programs. Template for C++ programs (save as template.cpp) – use for all programs
Explanation / Answer
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
double x1, y1, r1;
double x2, y2, r2;
double distanceBetweenTwoCenters;
System.out.print("Enter circle1's center x-, y-coordinates, and radius:");
x1 = s.nextDouble();
y1 = s.nextDouble();
r1 = s.nextDouble();
System.out.print("Enter circle2's center x-, y-coordinates, and radius:");
x2 = s.nextDouble();
y2 = s.nextDouble();
r2 = s.nextDouble();
distanceBetweenTwoCenters = Math.pow(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2), 0.5);
if(distanceBetweenTwoCenters <= r1 - r2) {
System.out.print("circle2 is inside circle1.");
} else if(distanceBetweenTwoCenters <= r1 + r2) {
System.out.print("circle2 overlaps circle1.");
} else {
System.out.print("circle2 does not overlap circle1.");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.