41 lines
894 B
C++

//
// Created by Nik on 10/04/2022.
//
#include "Triangle.h"
Triangle::Triangle(ColorCode color, unsigned int width) :
Shape2D(color), width(width) {}
unsigned int Triangle::getSurfaceArea() const {
unsigned int res = 0;
unsigned int rec = 1;
for (int i = 0; i < width; i++) {
res += rec;
rec++;
}
return res;
}
void Triangle::draw() const {
unsigned int rec = 1;
for (int i = 0; i < width; i++) {
for (int j = 0; j < rec; j++) PrintUtility::print(color," *");
rec++;
std::cout << "\n";
}
std::cout << "\n";
}
std::string Triangle::getString() const {
std::string ret;
unsigned int rec = 1;
for (int i = 0; i < width; i++) {
for (int j = 0; j < rec; j++) ret += " *";
rec++;
ret += "\n";
}
ret += "\n";
return ret;
}