C++ Program to Find Surface Area and Volume of a Cone

C++ Program to Find Surface Area and Volume of a Cone

C++ Program to Find Surface Area and Volume of a Cone


Introduction

The cone is a three-dimensional geometric shape with a circular base and a pointed tip known as the vertex. In various mathematical and engineering applications, calculating the surface area and volume of a cone is important. This program demonstrates how to compute these values using C++.

The formulae for surface area and volume involve basic geometry and are easy to implement programmatically. By providing the radius of the base and the height of the cone, we can determine both the lateral and total surface area, as well as the volume.


Formulae

To calculate the surface area and volume of a cone, we use the following formulae:

  • Lateral Surface Area (LSA): Ï€ * r * l, where r is the radius of the base and l is the slant height.
  • Total Surface Area (TSA): Ï€ * r * (r + l), where r is the radius, and l is the slant height.
  • Volume: (1/3) * Ï€ * r2 * h, where r is the radius, and h is the height of the cone.
  • The slant height l can be calculated using the Pythagorean theorem: l = √(r2 + h2).

Code

#include <iostream>
#include <cmath>

using namespace std;

int main() {
    double radius, height, slantHeight, lateralSurfaceArea, totalSurfaceArea, volume;

    // Input the radius and height of the cone
    cout << "Enter the radius of the cone: ";
    cin >> radius;
    cout << "Enter the height of the cone: ";
    cin >> height;

    // Calculate slant height
    slantHeight = sqrt((radius * radius) + (height * height));

    // Calculate lateral surface area
    lateralSurfaceArea = M_PI * radius * slantHeight;

    // Calculate total surface area
    totalSurfaceArea = M_PI * radius * (radius + slantHeight);

    // Calculate volume
    volume = (1.0 / 3) * M_PI * radius * radius * height;

    // Display the results
    cout << "Slant Height: " << slantHeight << endl;
    cout << "Lateral Surface Area: " << lateralSurfaceArea << endl;
    cout << "Total Surface Area: " << totalSurfaceArea << endl;
    cout << "Volume: " << volume << endl;

    return 0;
}
    

Output

When you run the program, it will prompt you to enter the radius and height of the cone. Based on the input, it calculates and displays the slant height, lateral surface area, total surface area, and volume of the cone.

Example:

Enter the radius of the cone: 3
Enter the height of the cone: 4
Slant Height: 5
Lateral Surface Area: 47.1239
Total Surface Area: 75.3982
Volume: 37.6991
    

Explanation

The program first takes the radius and height as input from the user. It then calculates the slant height using the Pythagorean theorem:

  • slantHeight = sqrt((radius * radius) + (height * height));

Once the slant height is determined, the program computes the lateral surface area and total surface area using the formulae:

  • lateralSurfaceArea = M_PI * radius * slantHeight;
  • totalSurfaceArea = M_PI * radius * (radius + slantHeight);

Finally, the program calculates the volume of the cone:

  • volume = (1.0 / 3) * M_PI * radius * radius * height;

The M_PI constant is used to represent the value of π. Each calculated result is then displayed to the user in a readable format.


Conclusion

This program demonstrates how to calculate the surface area and volume of a cone using simple mathematical formulae in C++. By using the cmath library, we efficiently compute the slant height and other derived properties of the cone.