24 May
2022
24 May
'22
10:12 p.m.
#include <iostream> using namespace std; class Triangle { public: Triangle(int width, int height) : width(width), height(height) { } void draw() { int start_offset = width / 2; int end_offset = 0; for (int row = 0; row < height; ++ row) { int bgratio = (end_offset - start_offset) * row / height + start_offset; lineOf(' ', bgratio); lineOf('*', width - bgratio); lineOf(' ', bgratio); cout << endl; } } private: int width, height; void lineOf(char ch, int count) { for(; count; -- count) cout << ch; } } int main() { Triangle triangle; triangle.draw(); } time to test it