2022.11.01 House drawing

 avatar
VikiePikie
c_cpp
2 years ago
944 B
6
Indexable
#include <iostream>
#define repeat(code, i, n) for (int i = 0; i < (n); i++) (code);

struct stroke {
	stroke(int length, char symbol = ' ') : n(length), c(symbol) {}
	int n; char c;
};

struct house {
	house(int width, int height) : w(width / 2), h(height) {}
	int w, h;
};

std::ostream& operator<< (std::ostream& out, const stroke& s) {
	repeat((out << s.c), i, s.n);
	return out;
}

std::ostream& operator<< (std::ostream& out, const house& h) {
	repeat(out << stroke(h.w - i - 1) << "/" << stroke(2 * i) << "\\\n", i, h.w - 2);
	repeat(out << " /"  << stroke(2 * h.w - 4, '-') << "\\\n",   i, 1);
	repeat(out << "/ |" << stroke(2 * h.w - 6) /**/ << "| \\\n", i, 1);
	repeat(out << "> |" << stroke(2 * h.w - 6) /**/ << "|\n",    i, h.h - 2);
	repeat(out << "> |" << stroke(2 * h.w - 6, '_') << "|\n",    i, 1);
	return out;
}

int main() {
	std::cout << "House Drawing:\n" << house(30, 7) << "\n";
	return 0;
}
Editor is loading...