Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions math/area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ template <typename T>
T cylinder_surface_area(T radius, T height) {
return 2 * M_PI * radius * height + 2 * M_PI * pow(radius, 2);
}

/**
* @brief surface area of a [hemi-sphere](https://en.wikipedia.org/wiki/Surface_area) ( 3 *
* pi * r^2)
* @param radius is the radius of the hemi-sphere
* @tparam T datatype of radius
* @returns surface area of the hemi-sphere
*/
template <typename T>
T hemi_sphere_surface_area(T radius) {
return 3 * M_PI * pow(radius, 2);
}
} // namespace math

/**
Expand Down Expand Up @@ -267,6 +279,18 @@ static void test() {
std::cout << "Output: " << double_area << std::endl;
assert(double_area == double_expected);
std::cout << "TEST PASSED" << std::endl << std::endl;

// 11th test
double_radius = 10.0;
double_expected = 942.4777960769379;
double_area = math::hemi_sphere_surface_area(double_radius);

std::cout << "SURFACE AREA OF A HEMI-SPHERE" << std::endl;
std::cout << "Input Radius: " << double_radius << std::endl;
std::cout << "Expected Output: " << double_expected << std::endl;
std::cout << "Output: " << double_area << std::endl;
assert(double_area == double_expected);
std::cout << "TEST PASSED" << std::endl << std::endl;
}

/**
Expand Down
Loading