Write a C++ program. Create class circle. Create a dynamic array of n cocentric circles.…
- User
Write a C++ program. Create class circle. Create a dynamic array of n cocentric circles. Their radius has to be equal to their number. Coordinates for point are entered. Then print the point and the circles in which it's inside
- Assistant
- User
Replace all the quote marks characters so that they're compilable
- Assistant
Certainly! Here is the correct version of the C++ program with proper quote marks. This version should compile without issues:
#include <iostream> #include <cmath> using namespace std; class Circle { private: double xCenter, yCenter, radius; public: Circle(double x, double y, double r) : xCenter(x), yCenter(y), radius(r) {} bool contains(double xPoint, double yPoint) { double dx = xCenter - xPoint; double dy = yCenter - yPoint; double distanceSquared = dx * dx + dy * dy; return distanceSquared <= radius * radius; } void print() { cout << "Circle with center (" << xCenter << ", " << yCenter << ") and radius " << radius << endl; } }; int main() { int n; cout << "Enter the number of concentric circles: "; cin >> n; // Assuming all circles are centered at the origin (0, 0) Circle** circles = new Circle*[n]; for (int i = 1; i <= n; i++) { circles[i - 1] = new Circle(0, 0, static_cast<double>(i)); } double x, y; cout << "Enter the x coordinate of the point: "; cin >> x; cout << "Enter the y coordinate of the point: "; cin >> y; cout << "The point (" << x << ", " << y << ") is inside the following circles:" << endl; bool insideAnyCircle = false; for (int i = 0; i < n; i++) { if (circles[i]->contains(x, y)) { insideAnyCircle = true; circles[i]->print(); } } if (!insideAnyCircle) { cout << "The point is not inside any circle." << endl; } // Clean up the dynamically allocated memory for (int i = 0; i < n; i++) { delete circles[i]; } delete[] circles; return 0; }