Without adding any method or function to the classes shown below. Find out the coverage of the canvas that encloses all the circles that are generated by the program. Circle 0: center = (x = 35.57, y = -36.60), radius = 92.27 Circle 1: center = (x = -18.04, y = -5.67), radius = 98.76 Circle 2: center = (x = -10.82, y = -45.88), radius = 111.03 Circle 3: center = (x = 48.97, y = 1.55), radius = 106.70 Circle 4: center = (x = -12.89, y = 4.64), radius = 86.49 Circle 5: center = (x = 19.07, y = 17.01), radius = 145.67 Circle 6: center = (x = 15.98, y = 12.89), radius = 139.18 Circle 7: center = (x = -3.61, y = -9.79), radius = 85.05 Circle 8: center = (x = -8.76, y = 44.85), radius = 98.76 Circle 9: center = (x = -39.69, y = -28.35), radius = 127.63 Circle 1 intersecting with Circle 4, 5, 6 Circle 3 intersecting with Circle 5 Circle 4 intersecting with Circle 5, 6 Circle 5 intersecting with Circle 6, 7, 8 Circle 6 intersecting with Circle 7 Circle 7 intersecting with Circle 9 Bye... Note that intersection display of circle i and j is based on the condition of i < j. You can submit up to two times. Use seed 123 for your submission. #include #include #include #include #include #include #include using namespace std; class Point { // cannot modify double m_x; double m_y; public: Point(const double a, const double b) : m_x(a), m_y(b) {} double x() const { return m_x; } double y() const { return m_y; } friend ostream& operator<<(ostream&, const Point&); }; class Circle { // cannot modify int id; Point center; double radius; public: Circle(const int n, const Point& p, const double r) : id(n), center(p), radius(r) {} bool operator<(const Circle&) const; friend ostream& operator<<(ostream&, const Circle&); }; double uniform(const double a, const double b) { assert(a < b); return a + (b - a) / 97. * (rand() % 98); } int main() { vector v; for (int i = 0; i < 10; ++i) v.push_back(Circle(i, Point(uniform(-50, 50), uniform(-50, 50)), uniform(80, 150))); for (int i = 0; i < 10; ++i) cout << v.at(i) << endl; cout << "Bye..." << endl; return 0; }
Without adding any method or function to the classes shown below. Find out the coverage of the canvas that encloses all the circles that are generated by the program.
Circle 0: center = (x = 35.57, y = -36.60), radius = 92.27
Circle 1: center = (x = -18.04, y = -5.67), radius = 98.76
Circle 2: center = (x = -10.82, y = -45.88), radius = 111.03
Circle 3: center = (x = 48.97, y = 1.55), radius = 106.70
Circle 4: center = (x = -12.89, y = 4.64), radius = 86.49
Circle 5: center = (x = 19.07, y = 17.01), radius = 145.67
Circle 6: center = (x = 15.98, y = 12.89), radius = 139.18
Circle 7: center = (x = -3.61, y = -9.79), radius = 85.05
Circle 8: center = (x = -8.76, y = 44.85), radius = 98.76
Circle 9: center = (x = -39.69, y = -28.35), radius = 127.63
Circle 1 intersecting with Circle 4, 5, 6
Circle 3 intersecting with Circle 5
Circle 4 intersecting with Circle 5, 6
Circle 5 intersecting with Circle 6, 7, 8
Circle 6 intersecting with Circle 7
Circle 7 intersecting with Circle 9
Bye...
Note that intersection display of circle i and j is based on the condition of i < j. You can submit up to two times. Use seed 123 for your submission.
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <
#include <algorithm>
#include <cmath>
#include <cassert>
using namespace std;
class Point { // cannot modify
double m_x;
double m_y;
public:
Point(const double a, const double b) : m_x(a), m_y(b) {}
double x() const { return m_x; }
double y() const { return m_y; }
friend ostream& operator<<(ostream&, const Point&);
};
class Circle { // cannot modify
int id;
Point center;
double radius;
public:
Circle(const int n, const Point& p, const double r) : id(n), center(p), radius(r) {}
bool operator<(const Circle&) const;
friend ostream& operator<<(ostream&, const Circle&);
};
double uniform(const double a, const double b) {
assert(a < b);
return a + (b - a) / 97. * (rand() % 98);
}
int main() {
vector<Circle> v;
for (int i = 0; i < 10; ++i) v.push_back(Circle(i, Point(uniform(-50, 50), uniform(-50, 50)), uniform(80, 150)));
for (int i = 0; i < 10; ++i) cout << v.at(i) << endl;
cout << "Bye..." << endl;
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images