-
Notifications
You must be signed in to change notification settings - Fork 2
/
Cube.h
160 lines (138 loc) · 3.44 KB
/
Cube.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
//
// Created by Ryan.Zurrin001 on 12/15/2021.
//
#ifndef PHYSICSFORMULA_CUBE_H
#define PHYSICSFORMULA_CUBE_H
/**
* @class Cube
* @details Cube class that represents a cube object
* @author Ryan Zurrin
* @dateBuilt 11/4/2021
* @lastEdit 11/4/2021
*/
#include <iostream>
#include <cmath>
static int cubeObjectCount = 0;
typedef long double ld;
class Cube
{
ld side;
ld surfaceArea;
ld volume;
static auto countIncrease() { cubeObjectCount += 1; }
static auto countDecrease() { cubeObjectCount -= 1; }
ld calculateSide()const;
ld calculateSurfaceArea()const;
ld calculateVolume()const;
public:
Cube()
{
side = 0.0;
surfaceArea = 0.0;
volume = 0.0;
countIncrease();
}
Cube(ld side)
{
this->side = side;
this->surfaceArea = calculateSurfaceArea();
this->volume = calculateVolume();
countIncrease();
}
/**
* @brief copy constructor
*/
Cube(const Cube& s)
{
side = s.side;
surfaceArea = s.surfaceArea;
volume = s.volume;
countIncrease();
}
/**
* #brief move constructor
*/
Cube(Cube&& s) noexcept
{
side = s.side;
surfaceArea = s.surfaceArea;
volume = s.volume;
countIncrease();
}
/**
* @brief copy assignment operator
*/
Cube& operator=(Cube&& s) noexcept
{
if (this != &s)
{
side = s.side;
surfaceArea = s.surfaceArea;
volume = s.volume;
countIncrease();
}
return *this;
}
Cube& operator=(Cube other)
{
std::swap(side, other.side);
std::swap(surfaceArea, other.surfaceArea);
std::swap(volume, other.volume);
return *this;
}
static void show_objectCount() {
std::cout << "\n cube object count: "
<< cubeObjectCount << std::endl;
}
static int get_objectCount() { return cubeObjectCount; }
~Cube() = default;
auto setSide(ld s);
auto setSurfaceArea(ld sa);
auto setVolume(ld v);
[[nodiscard]] auto getSide() const { return side; }
[[nodiscard]] auto getSurfaceArea() const { return surfaceArea; }
[[nodiscard]] auto getVolume() const { return volume; }
[[nodiscard]] auto getWeight(ld densityKgM) const;
void printCubeInfo()const;
};
#endif //PHYSICSFORMULA_CUBE_H
inline ld Cube::calculateSide() const
{
return std::cbrt(volume);
}
inline ld Cube::calculateSurfaceArea() const
{
return 6.0 * (side * side);
}
inline ld Cube::calculateVolume() const
{
return (side*side*side);
}
inline auto Cube::setSide(ld s)
{
side = s;
volume = calculateVolume();
surfaceArea = calculateSurfaceArea();
}
inline auto Cube::setSurfaceArea(ld sa)
{
surfaceArea = sa;
side = sqrt(surfaceArea / 6);
volume = calculateVolume();
}
inline auto Cube::setVolume(ld v)
{
volume = v;
side = calculateSide();
surfaceArea = calculateSurfaceArea();
}
inline auto Cube::getWeight(ld densityKgM) const
{
return densityKgM * volume;
}
inline void Cube::printCubeInfo() const
{
std::cout << "side: " << side << std::endl;
std::cout << "surface area: " << surfaceArea << std::endl;
std::cout << "volume: " << volume << std::endl;
}