-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCylinder.h
More file actions
154 lines (135 loc) · 3.69 KB
/
Cylinder.h
File metadata and controls
154 lines (135 loc) · 3.69 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
//
// Created by Ryan.Zurrin001 on 12/15/2021.
//
#ifndef PHYSICSFORMULA_CYLINDER_H
#define PHYSICSFORMULA_CYLINDER_H
/**
* @class Cylinder
* @details class to represent a Cylinder object
* @author Ryan Zurrin
* @dateBuilt 11/4/2021
* @lastEdit 11/4/2021
*/
#include <iostream>
#define PI_ 3.14159265358979323846
static int cylinderObjectCount = 0;
typedef long double ld;
class Cylinder
{
ld height;
ld radius;
ld volume;
ld surfaceArea;
static auto countIncrease() { cylinderObjectCount += 1; }
static auto countDecrease() { cylinderObjectCount -= 1; }
ld calculateVolume()const;
ld calculateSurfaceArea()const;
public:
Cylinder()
{
height = 0.0;
radius = 0.0;
volume = 0.0;
surfaceArea = 0.0;
countIncrease();
}
Cylinder(ld height, ld radius)
{
this->height = height;
this->radius = radius;
this->volume = calculateVolume();
this->surfaceArea = calculateSurfaceArea();
countIncrease();
}
/**
* @brief copy constructor
*/
Cylinder(const Cylinder& s)
{
height = s.height;
radius = s.radius;
volume = s.volume;
surfaceArea = s.surfaceArea;
countIncrease();
}
/**
* #brief move constructor
*/
Cylinder(Cylinder&& s) noexcept
{
height = s.height;
radius = s.radius;
volume = s.volume;
surfaceArea = s.surfaceArea;
countIncrease();
}
/**
* @brief copy assignment operator
*/
Cylinder& operator=(Cylinder&& s) noexcept
{
if (this != &s)
{
height = s.height;
radius = s.radius;
volume = s.volume;
surfaceArea = s.surfaceArea;
countIncrease();
}
return *this;
}
Cylinder& operator=(Cylinder other)
{
std::swap(height, other.height);
std::swap(radius, other.radius);
std::swap(volume, other.volume);
std::swap(surfaceArea, other.surfaceArea);
return *this;
}
static void show_objectCount() {
std::cout << "\n cylinder object count: "
<< cylinderObjectCount << std::endl;
}
static int get_objectCount() { return cylinderObjectCount; }
~Cylinder() = default;
auto setHeight(ld h);
auto setRadius(ld r);
[[nodiscard]] auto getHeight() const { return height; }
[[nodiscard]] auto getRadius() const { return radius; }
[[nodiscard]] auto getVolume() const { return volume; }
[[nodiscard]] auto getSurfaceArea() const { return surfaceArea; }
[[nodiscard]] auto getWeight(ld densityKgM) const;
void printCylinderInfo()const;
};
#endif //PHYSICSFORMULA_CYLINDER_H
inline ld Cylinder::calculateVolume() const
{
return PI_ * (radius*radius) * height;
}
inline ld Cylinder::calculateSurfaceArea() const
{
return 2.0 * PI_ * (radius * radius) + 2.0 * PI_ * radius * height;
}
inline auto Cylinder::setHeight(ld h)
{
height = h;
volume = calculateVolume();
surfaceArea = calculateSurfaceArea();
}
inline auto Cylinder::setRadius(ld r)
{
radius = r;
volume = calculateVolume();
surfaceArea = calculateSurfaceArea();
}
inline auto Cylinder::getWeight(ld densityKgM) const
{
return densityKgM * volume;
}
inline void Cylinder::printCylinderInfo() const
{
std::cout << "height: " << height << std::endl;
std::cout << "radius: " << radius << std::endl;
std::cout << "volume: " << volume << std::endl;
std::cout << "surface area: " << surfaceArea << std::endl;
}