Skip to content

Commit 807913a

Browse files
Add area of hemi-sphere
1 parent 0ecb6bd commit 807913a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

math/area.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ template <typename T>
109109
T cylinder_surface_area(T radius, T height) {
110110
return 2 * M_PI * radius * height + 2 * M_PI * pow(radius, 2);
111111
}
112+
113+
/**
114+
* @brief surface area of a [hemi-sphere](https://en.wikipedia.org/wiki/Surface_area) ( 3 *
115+
* pi * r^2)
116+
* @param radius is the radius of the hemi-sphere
117+
* @returns surface area of the hemi-sphere
118+
*/
119+
template <typename T>
120+
T hemi_sphere_surface_area(T radius) {
121+
return 3 * M_PI * pow(radius, 2);
122+
}
112123
} // namespace math
113124

114125
/**
@@ -267,6 +278,18 @@ static void test() {
267278
std::cout << "Output: " << double_area << std::endl;
268279
assert(double_area == double_expected);
269280
std::cout << "TEST PASSED" << std::endl << std::endl;
281+
282+
// 11th test
283+
double_radius = 10.0;
284+
double_expected = 942.4777960769379;
285+
double_area = math::hemi_sphere_surface_area(double_radius);
286+
287+
std::cout << "SURFACE AREA OF A HEMI-SPHERE" << std::endl;
288+
std::cout << "Input Radius: " << double_radius << std::endl;
289+
std::cout << "Expected Output: " << double_expected << std::endl;
290+
std::cout << "Output: " << double_area << std::endl;
291+
assert(double_area == double_expected);
292+
std::cout << "TEST PASSED" << std::endl << std::endl;
270293
}
271294

272295
/**

0 commit comments

Comments
 (0)