-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRectangularPrism.h
More file actions
174 lines (150 loc) · 4.4 KB
/
Copy pathRectangularPrism.h
File metadata and controls
174 lines (150 loc) · 4.4 KB
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
//
// Created by Ryan.Zurrin001 on 12/16/2021.
//
#ifndef PHYSICSFORMULA_RECTANGULARPRISM_H
#define PHYSICSFORMULA_RECTANGULARPRISM_H
/**
* @class RectangularPrism
* @details rectangularPrism class that represents a rectangular prism object
* @author Ryan Zurrin
* @dateBuilt 11/4/2021
* @lastEdit 11/4/2021
*/
#include <iostream>
static int rectangularPrismObjectCount = 0;
typedef long double ld;
class RectangularPrism
{
ld lenght;
ld width;
ld height;
ld volume;
ld surfaceArea;
static auto countIncrease() { rectangularPrismObjectCount += 1; }
static auto countDecrease() { rectangularPrismObjectCount -= 1; }
ld calculateVolume()const;
ld calculateSurfaceArea()const;
public:
RectangularPrism()
{
lenght = 0.0;
width = 0.0;
height = 0.0;
volume = 0.0;
surfaceArea = 0.0;
countIncrease();
}
RectangularPrism(ld length, ld width, ld height)
{
this->lenght = length;
this->width = width;
this->height = height;
this->volume = calculateVolume();
this->surfaceArea = calculateSurfaceArea();
countIncrease();
}
/**
* @brief copy constructor
*/
RectangularPrism(const RectangularPrism& s)
{
lenght = s.lenght;
width = s.width;
height = s.height;
volume = s.volume;
surfaceArea = s.surfaceArea;
countIncrease();
}
/**
* #brief move constructor
*/
RectangularPrism(RectangularPrism&& s) noexcept
{
lenght = s.lenght;
width = s.width;
height = s.height;
volume = s.volume;
surfaceArea = s.surfaceArea;
countIncrease();
}
/**
* @brief copy assignment operator
*/
RectangularPrism& operator=(RectangularPrism&& s) noexcept
{
if (this != &s)
{
lenght = s.lenght;
width = s.width;
height = s.height;
volume = s.volume;
surfaceArea = s.surfaceArea;
countIncrease();
}
return *this;
}
RectangularPrism& operator=(RectangularPrism other)
{
std::swap(lenght, other.lenght);
std::swap(width, other.width);
std::swap(height, other.height);
std::swap(volume, other.volume);
std::swap(surfaceArea, other.surfaceArea);
return *this;
}
static void show_objectCount() {
std::cout << "\n rectangle object count: "
<< rectangularPrismObjectCount << std::endl;
}
static int get_objectCount() { return rectangularPrismObjectCount; }
~RectangularPrism() = default;
auto setWidth(ld w);
auto setLength(ld l);
auto setHeight(ld h);
[[nodiscard]] auto getWidth() const { return width; }
[[nodiscard]] auto getLength() const { return lenght; }
[[nodiscard]] auto getHeight() const { return height; }
[[nodiscard]] auto getVolume() const { return volume; }
[[nodiscard]] auto getSurfaceArea() const { return surfaceArea; }
[[nodiscard]] auto getWeight(ld densityKgM) const;
void printRectangularPrismInfo()const;
};
#endif //PHYSICSFORMULA_RECTANGULARPRISM_H
inline ld RectangularPrism::calculateVolume() const
{
return lenght * width * height;
}
inline ld RectangularPrism::calculateSurfaceArea() const
{
return 2.0 * (lenght * width) + 2.0 * (lenght * height) + 2.0 * (width * height);
}
inline auto RectangularPrism::setWidth(ld w)
{
width = w;
surfaceArea = calculateSurfaceArea();
volume = calculateVolume();
}
inline auto RectangularPrism::setLength(ld l)
{
lenght = l;
surfaceArea = calculateSurfaceArea();
volume = calculateVolume();
}
inline auto RectangularPrism::setHeight(ld h)
{
height = h;
surfaceArea = calculateSurfaceArea();
volume = calculateVolume();
}
inline auto RectangularPrism::getWeight(ld densityKgM) const
{
return densityKgM * volume;
}
inline void RectangularPrism::printRectangularPrismInfo() const
{
std::cout << "length: " << lenght << std::endl;
std::cout << "width: " << width << std::endl;
std::cout << "height: " << height << std::endl;
std::cout << "volume: " << volume << std::endl;
std::cout << "surface area: " << surfaceArea << std::endl;
}