Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you please add comments to this for c++ #include #include #include #include #include #include #include #include using namespace std; class Circle //class { public:

Can you please add comments to this for c++

#include #include #include #include #include #include #include #include

using namespace std;

class Circle //class { public: void DrawCircles(string filename) //draws circles { int x, y, r, code; ifstream infile(filename); vector v; while (infile >> x >> y >> r >> code) { auto z = points(x, y, r, code); v.insert(v.end(), z.begin(), z.end()); } sort(v.begin(), v.end(), [](const point& a, const point& b) -> bool { if (a.x != b.x)return a.x < b.x; return a.y < b.y; }); print_points(v); } private: struct point { int x; int y; int col; }; const int MX_COL = 500; vector points(int x, int y, int n, int code) { float j, i, p; n = n + 3; p = floor((4 * n - 2.5) / 5.8); vector ans; int mnx = p, mny = n; for (j = p; j >= -p; j--) { for (i = -n; i <= n; i++) { if (p * p * i * i + n * n * j * j <= n * n * p * p) { int jj = j; int ii = i; ; ans.push_back({ jj, ii, code }); mnx = min(mnx, jj); mny = min(mny, ii); } } } for (auto& p : ans) { p.x -= mnx; p.y -= mny; p.x += x; p.y += y; assert(p.y < MX_COL); } return ans; } void col_print(int code, string s) { cout << "\033[" << code << "m" << s << "\033[0m"; } void print_points(vector& v) { int ind = 0; int tot = v.size(); for (int r = 0; ind < tot; r++) { for (int c = 0; c < MX_COL && ind < tot; c++) { if (v[ind].x > r) break; else { assert(v[ind].x == r); if (v[ind].y > c) cout << " "; else { assert(v[ind].y == c); col_print(v[ind].col, "*"); ind++; } } } cout << " "; } } }; int main() { float n, j, i, p; cout << "enter n "; cin >> n; n = n + 3; p = floor((4 * n - 2.5) / 5.8); for (j = p; j >= -p; j--) { for (i = -n; i <= n; i++) { if (p * p * i * i + n * n * j * j <= n * n * p * p) cout << "*"; else { cout << " "; } } cout << endl; } return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions