Другие языки программирования и технологии

Программирование на С++

Как сделать что бы консоль выводила не только координаты, но и рисовала этот квадрат. сказали что надписи после координат закрывает рисунок, как их тогда убрать.
#include <Windows.h>
#include <iostream>
using namespace std;
struct Coord {
Coord(int x, int y) : x(x), y(y) {}
int x;
int y;
friend ostream& operator<<(ostream& out, const Coord& p) {
out << "{ " << p.x << ", " << p.y << " }";
return out;
}
};
struct Rect {
Coord tl;
Coord br;
Rect(const Coord& tl, const Coord& br) : tl(tl), br(br) {}
Rect(Coord&& tl, Coord&& br) : tl(move(tl)), br(move(br)) {}
void draw()const {
const auto white = RGB(255, 255, 255);
const auto hwnd = GetConsoleWindow();
const auto hdc = GetDC(hwnd);
for (auto x = tl.x; x <= br.x; ++x) SetPixel(hdc, x, tl.y, white);
for (auto y = tl.y; y <= br.y; ++y) SetPixel(hdc, tl.x, y, white);
for (auto y = tl.y; y <= br.y; ++y) SetPixel(hdc, br.x, y, white);
for (auto x = tl.x; x <= br.x; ++x) SetPixel(hdc, x, br.y, white);
ReleaseDC(hwnd, hdc);
}
friend ostream& operator<<(ostream& out, const Rect& r) {
Coord tr(r.br.x, r.tl.y), bl(r.tl.x, r.br.y);
out << r.tl << '\n' << tr << '\n' << bl << '\n' << r.br;
return out;
}
};
int main() {
// Даны координаты левого верхнего угла квадрата
auto x = 50, y = 100;
// и длина его стороны
auto side = 150;
Coord a(x, y);
Coord b(x + side, y + side);
Rect rect(a, b);
cout << rect << '\n';
rect.draw();
cin.get();
}
РП
Роман Павлюченко
92 484
Лучший ответ