-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRectangle.h
197 lines (155 loc) · 5.14 KB
/
Rectangle.h
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
//
// Created by Ryan.Zurrin001 on 12/16/2021.
//
#ifndef PHYSICSFORMULA_RECTANGLE_H
#define PHYSICSFORMULA_RECTANGLE_H
/**
* @class Rectangle
* @details rectangle class that represents a rectangle object
* @author Ryan Zurrin
* @dateBuilt 11/4/2021
* @lastEdit 11/4/2021
*/
#include <iostream>
static int rectangleObjectCount = 0;
typedef long double ld;
namespace rez {
class Rectangle {
ld lenght;
ld width;
ld diagnal;
ld perimeter;
ld area;
static auto countIncrease() { rectangleObjectCount += 1; }
static auto countDecrease() { rectangleObjectCount -= 1; }
ld calculateLength() const;
ld calculateWidth() const;
ld calculateDiagnal() const;
ld calculatePerimeter() const;
ld calculateArea() const;
public:
Rectangle() {
lenght = 0.0;
width = 0.0;
diagnal = 0.0;
perimeter = 0.0;
area = 0.0;
countIncrease();
}
Rectangle(ld length, ld width) {
this->lenght = length;
this->width = width;
this->diagnal = calculateDiagnal();
this->perimeter = calculatePerimeter();
this->area = calculateArea();
countIncrease();
}
/**
* @brief copy constructor
*/
Rectangle(const Rectangle &s) {
lenght = s.lenght;
width = s.width;
diagnal = s.diagnal;
perimeter = s.perimeter;
area = s.area;
countIncrease();
}
/**
* #brief move constructor
*/
Rectangle(Rectangle &&s) noexcept {
lenght = s.lenght;
width = s.width;
diagnal = s.diagnal;
perimeter = s.perimeter;
area = s.area;
countIncrease();
}
/**
* @brief copy assignment operator
*/
Rectangle &operator=(Rectangle &&s) noexcept {
if (this != &s) {
lenght = s.lenght;
width = s.width;
diagnal = s.diagnal;
perimeter = s.perimeter;
area = s.area;
countIncrease();
}
return *this;
}
Rectangle &operator=(Rectangle other) {
std::swap(lenght, other.lenght);
std::swap(width, other.width);
std::swap(diagnal, other.diagnal);
std::swap(perimeter, other.perimeter);
std::swap(area, other.area);
return *this;
}
static void show_objectCount() {
std::cout << "\n rectangle object count: "
<< rectangleObjectCount << std::endl;
}
static int get_objectCount() { return rectangleObjectCount; }
~Rectangle() = default;
auto setWidth(ld w);
auto setLength(ld l);
auto setPerimeter(ld p);
auto setArea(ld a);
[[nodiscard]] auto getWidth() const { return width; }
[[nodiscard]] auto getLength() const { return lenght; }
[[nodiscard]] auto getDiagnol() const { return diagnal; }
[[nodiscard]] auto getPerimeter() const { return perimeter; }
[[nodiscard]] auto getArea() const { return area; }
void printRectangleInfo() const;
};
#endif //PHYSICSFORMULA_RECTANGLE_H
inline ld Rectangle::calculateLength() const {
return (perimeter * sqrt((perimeter * perimeter) - 8.0 * area)) / 2.0;
}
inline ld Rectangle::calculateWidth() const {
return area / lenght;
}
inline ld Rectangle::calculateDiagnal() const {
return sqrt((lenght * lenght) + (width * width));
}
inline ld Rectangle::calculatePerimeter() const {
return 2.0 * (lenght + width);
}
inline ld Rectangle::calculateArea() const {
return lenght * width;
}
inline auto Rectangle::setWidth(ld w) {
width = w;
perimeter = calculatePerimeter();
area = calculateArea();
diagnal = calculateDiagnal();
}
inline auto Rectangle::setLength(ld l) {
lenght = l;
perimeter = calculatePerimeter();
area = calculateArea();
diagnal = calculateDiagnal();
}
inline auto Rectangle::setPerimeter(ld p) {
perimeter = p;
lenght = calculateLength();
width = calculateWidth();
diagnal = calculateDiagnal();
}
inline auto Rectangle::setArea(ld a) {
area = a;
lenght = calculateLength();
width = calculateWidth();
diagnal = calculateDiagnal();
}
inline void Rectangle::printRectangleInfo() const {
std::cout << "length: " << lenght << std::endl;
std::cout << "width: " << width << std::endl;
std::cout << "diagonal: " << diagnal << std::endl;
std::cout << "perimeter: " << perimeter << std::endl;
std::cout << "area: " << area << std::endl;
}
}