consolidate all repos to one for archive
This commit is contained in:
40
semester_2/programiranje_2/naloga0601/Triangle.cpp
Normal file
40
semester_2/programiranje_2/naloga0601/Triangle.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
Reference in New Issue
Block a user