Program to calculate Volume and Surface area of Hemisphere


A sphere is a three-dimensional geometric shape that is perfectly round like a ball, while a hemisphere is one half of a sphere. In essence, a sphere would split into two hemispheres if it were sliced in half. Hemispheres are identified by their curving surface, which radiates out from the sphere's core. The Greek terms "hemi" (half) and "sphaira" (sphere) are where the name "hemisphere" comes from. Hemispheres are used to describe and simulate a variety of events in a number of disciplines, including geography, astronomy, mathematics, and physics.

Volume of a Hemisphere

The volume of a hemisphere is equal to half the volume of the corresponding sphere, and can be calculated using the following formula, where V represents the volume and r is the radius of the hemisphere.

$$\mathrm{V=(2/3) \pi r^3}$$

Surface Area of a Hemisphere

The surface area of a hemisphere is the total area covered by its curved surface. It can be calculated using the formula, where A represents the surface area and r is the radius of the hemisphere. This formula represents the sum of the curved surface area of the hemisphere and the area of its flat circular base.

$$\mathrm{A=2 \pi r^2}$$

Problem Statement

The aim of this problem is to calculate the volume and surface area of a hemisphere of a given radius.

Sample Examples

Input

r = 5

Output

Volume = 261.799
Surface Area = 157.08

Explanation

Substituting the value of r in the formulas, we can calculate the surface area and volume of a hemisphere.

Input

r = 11

Output

Volume = 3619.11
Surface Area = 904.779

Explanation

Substituting the value of r in the formulas, we can calculate the surface area and volume of a hemisphere.

Input

r = 1

Output

Volume = 2.0944
Surface Area = 6.28319

Explanation

Substituting the value of r in the formulas, we can calculate the surface area and volume of a hemisphere.

Solution Approach

In order to compute the surface area and volume of a hemisphere, of a given radius r, we can directly substitute the value of the given radius in the formula and derive the answers.

The approach consists of the following steps:

  • Calculate the volume of the hemisphere using the formula V = (2/3)πr3. This formula represents half the volume of the corresponding sphere, which is the total volume of the hemisphere.

  • Calculate the surface area of the hemisphere using the formula A = 2πr2. This formula represents the sum of the curved surface area of the hemisphere and the area of its flat circular base.

  • Substitute the value of the radius into the relevant formula to obtain the volume or surface area of the hemisphere.

Algorithm

  • We define two separate functions called hemisphere_volume() and hemisphere_surface_area() that take the radius of the hemisphere as a parameter and return the volume and surface area of the hemisphere, respectively.

  • Inside each function, we define a constant double variable called PI and initialize it to the approximate value of pi.

  • In the hemisphere_volume() function, we calculate the volume of the hemisphere using the formula (4/3) * PI * r3 / 2, where r is the radius. Since we're only interested in half of the sphere, we divide the result by 2 and return it.

  • In the hemisphere_surface_area() function, we calculate the surface area of the hemisphere using the formula 2 * PI * r2 and return it.

  • In the main() function, we define and initialize the radius.

  • We call the hemisphere_volume() and hemisphere_surface_area() functions with the radius as a parameter to calculate the volume and surface area of the hemisphere, respectively.

  • We output the results.

Example:C++ Program

The following C++ program computes the volume and surface area of a hemisphere by calling the functions hemisphere_volume() and hemisphere_surface_area(), respectively, in the main function.

// c++ code to compute the volume and surface area of a hemisphere
#include <iostream>
using namespace std;
// function to compute the volume of the hemisphere
double hemisphere_volume(double radius) {
    const double PI = 3.14159265358979323846;
    return (4.0/3.0) * PI * radius * radius * radius / 2.0;
}
// function to compute the surface area of the hemisphere
double hemisphere_surface_area(double radius) {
    const double PI = 3.14159265358979323846;
    return 2.0 * PI * radius * radius;
}
// driver code
int main() {
    double radius, volume, surface_area;
    radius = 10;
    volume = hemisphere_volume(radius); // function call
    surface_area = hemisphere_surface_area(radius); // function call
    cout << "Volume =  " << volume << endl;
    cout << "Surface Area = " << surface_area << endl;
    return 0;
}

Output

Volume = 2094.4
Surface Area = 628.319

Time and Space Complexity Analysis

Time complexity: O(1)

The program only performs normal arithmetic operations, which are implemented in constant time. Therefore, the running time of the program does not depend on the size of the input.

Space complexity: O(1)

The program uses a fixed amount of memory to store the variables and constants that it uses, regardless of the input size. The variables used in the program are all of constant size, which means that the space complexity is also O(1).

Conclusion

In conclusion, the algorithm presented in this article provides a straightforward and efficient way to compute the volume and surface area of a hemisphere in constant time without the use of auxiliary space. The article discusses the basic properties of a hemisphere. It also provides the solution approach, the algorithm used and the C++ program solution as well, along with an in depth analysis of its time complexity and space complexity.

Updated on: 08-Sep-2023

147 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements