-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRightTriangle.cpp
More file actions
40 lines (31 loc) · 1011 Bytes
/
RightTriangle.cpp
File metadata and controls
40 lines (31 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "RightTriangle.h"
#include<math.h>
using namespace std;
RightTriangle::RightTriangle(int h, const string &d) : Triangle(h, h, "RightTriangle", d) { }
RightTriangle::~RightTriangle() = default;
const RightTriangle &RightTriangle::operator=(const RightTriangle &rhs) {
Triangle::operator=(rhs);
return *this;
}
void RightTriangle::scale(int n) {
if (getHeight() + n > 0) {
setHeight(getHeight() + n);
setBase(getHeight() + n);
}
}
double RightTriangle::geoPerimeter() const {
return (2 + sqrt(2)) * getHeight(); // (2 + sqrt(2)) * h
}
int RightTriangle::scrArea() const {
return (getHeight() * (getHeight() + 1)) / 2;
}
int RightTriangle::scrPerimeter() const {
return 3 * (getHeight() - 1);
}
void RightTriangle::draw(Canvas &canvas, int c, int r, char fg, char bg) const {
for (int h = 0; h < getHeight(); h++) {
for (int w = 0; w <= h; w++) {
canvas.putChar(fg, c + h, r + w); // write to right side of c
}
}
}