Find the surface area of a cone
A cone is a three-dimensional geometric shape that has a circular base and a pointed top. Finding the surface area of a cone involves determining the total area covered by its curved surface.
Problem Statement
Given the radius of the base and the slant height of the cone, the task is to calculate its surface area. The formula for finding the surface area of a cone in terms of its radius 'r' and slant height 's' is:
Surface Area = π * r * s + π * r²
Example Scenario
Imagine you are a structural engineer working on designing a cone-shaped roof for a pavilion. To estimate the cost of materials needed to construct the roof, you need to calculate the surface area of the cone. By finding the surface area, you can ensure accurate budgeting and material procurement.
Idea to Solve the Problem
To solve this problem, we can follow these steps:
- Accept the radius of the cone's base and the slant height as inputs.
- Use the formula to calculate the surface area of the cone.
- Display the calculated surface area.
Pseudocode
function cone_surface_area(radius, slant_height):
area = π * radius * slant_height + π * (radius * radius)
return area
main:
radius1 = 4.3
slant_height1 = 7
radius2 = 5
slant_height2 = 8
radius3 = 6.2
slant_height3 = 8.3
area1 = cone_surface_area(radius1, slant_height1)
area2 = cone_surface_area(radius2, slant_height2)
area3 = cone_surface_area(radius3, slant_height3)
print("Given Radius :", radius1, "Slant Height", slant_height1)
print("Surface Area of Cone :", area1)
print("Given Radius :", radius2, "Slant Height", slant_height2)
print("Surface Area of Cone :", area2)
print("Given Radius :", radius3, "Slant Height", slant_height3)
print("Surface Area of Cone :", area3)
Algorithm Explanation
- Define a function
cone_surface_area
that takes the radius and slant height as inputs. - Inside the function, use the provided formula to calculate the surface area of the cone.
- In the
main
function, set three test cases with different values for the radius and slant height. - Calculate the surface areas for each test case by calling the
cone_surface_area
function. - Display the calculated surface areas along with their respective radius and slant height values.
Code Solution
/*
C Program
Find the surface area of a cone
*/
#include <stdio.h>
#include <math.h>
//Calculate surface area of a cone by given radius and slant height
void cone_surface_area(double radius, double slant_height)
{
// Formula of cone area
// π * r * s + π * r²
// here r is radius
// s is slant_height
//Display given inputs
printf("\nGiven Radius : %lf Slant Height %lf", radius, slant_height);
//Calculate surface area of cone
double area = M_PI * radius * slant_height + M_PI * (radius * radius);
//Display surface area
printf("\nSurface area of cone %lf\n", area);
}
int main()
{
//Simple Case
cone_surface_area(4.3, 7);
cone_surface_area(5, 8);
cone_surface_area(6.2, 8.3);
return 0;
}
Output
Given Radius : 4.300000 Slant Height 7.000000
Surface area of cone 152.649987
Given Radius : 5.000000 Slant Height 8.000000
Surface area of cone 204.203522
Given Radius : 6.200000 Slant Height 8.300000
Surface area of cone 282.429180
// Java Program
// Find the surface area of a cone
class Cone
{
//Calculate surface area of a cone by given radius and slant height
public void surface_area(double radius, double slant_height)
{
// Formula of cone area
// π * r * s + π * r²
// here r is radius
// s is slant_height
//Display given inputs
System.out.print("\nGiven Radius : " + radius + " Slant Height " + slant_height);
//Calculate surface area of cone
double area = Math.PI * radius * slant_height + Math.PI * (radius * radius);
//Display surface area
System.out.print("\nSurface area of cone " + area + "\n");
}
public static void main(String[] args)
{
Cone cone = new Cone();
//Simple Case
cone.surface_area(4.3, 7);
cone.surface_area(5, 8);
cone.surface_area(6.2, 8.3);
}
}
Output
Given Radius : 4.3 Slant Height 7.0
Surface area of cone 152.64998703792804
Given Radius : 5.0 Slant Height 8.0
Surface area of cone 204.20352248333654
Given Radius : 6.2 Slant Height 8.3
Surface area of cone 282.4291795577224
// C++ Program
// Find the surface area of a cone
#include<iostream>
#include<math.h>
using namespace std;
class Cone
{
public:
//Calculate surface area of a cone by given radius and slant height
void surface_area(double radius, double slant_height)
{
cout << "\nGiven Radius : " << radius << " Slant Height " << slant_height;
//Calculate surface area of cone
double area = M_PI * radius * slant_height + M_PI * (radius * radius);
cout << "\nSurface area of cone " << area << "\n";
}
};
int main()
{
Cone cone;
//Simple Case
cone.surface_area(4.3, 7);
cone.surface_area(5, 8);
cone.surface_area(6.2, 8.3);
return 0;
}
Output
Given Radius : 4.3 Slant Height 7
Surface area of cone 152.65
Given Radius : 5 Slant Height 8
Surface area of cone 204.204
Given Radius : 6.2 Slant Height 8.3
Surface area of cone 282.429
// C# Program
// Find the surface area of a cone
using System;
class Cone
{
//Calculate surface area of a cone by given radius and slant height
public void surface_area(double radius, double slant_height)
{
Console.Write("\nGiven Radius : " + radius + " Slant Height " + slant_height);
//Calculate surface area of cone
double area = Math.PI * radius * slant_height + Math.PI * (radius * radius);
Console.Write("\nSurface area of cone " + area + "\n");
}
public static void Main(String[] args)
{
Cone cone = new Cone();
//Simple Case
cone.surface_area(4.3, 7);
cone.surface_area(5, 8);
cone.surface_area(6.2, 8.3);
}
}
Output
Given Radius : 4.3 Slant Height 7
Surface area of cone 152.649987037928
Given Radius : 5 Slant Height 8
Surface area of cone 204.203522483337
Given Radius : 6.2 Slant Height 8.3
Surface area of cone 282.429179557722
<?php
// Php Program
// Find the surface area of a cone
class Cone
{
//Calculate surface area of a cone by given radius and slant height
public function surface_area($radius, $slant_height)
{
echo "\nGiven Radius : ". $radius ." Slant Height ". $slant_height;
//Calculate surface area of cone
$area = M_PI * $radius * $slant_height + M_PI * ($radius * $radius);
echo "\nSurface area of cone ". $area ."\n";
}
}
function main()
{
$cone = new Cone();
//Simple Case
$cone->surface_area(4.3, 7);
$cone->surface_area(5, 8);
$cone->surface_area(6.2, 8.3);
}
main();
Output
Given Radius : 4.3 Slant Height 7
Surface area of cone 152.64998703793
Given Radius : 5 Slant Height 8
Surface area of cone 204.20352248334
Given Radius : 6.2 Slant Height 8.3
Surface area of cone 282.42917955772
// Node Js Program
// Find the surface area of a cone
class Cone
{
//Calculate surface area of a cone by given radius and slant height
surface_area(radius, slant_height)
{
process.stdout.write("\nGiven Radius : " + radius + " Slant Height " + slant_height);
//Calculate surface area of cone
var area = Math.PI * radius * slant_height + Math.PI * (radius * radius);
process.stdout.write("\nSurface area of cone " + area + "\n");
}
}
function main()
{
var cone = new Cone();
//Simple Case
cone.surface_area(4.3, 7);
cone.surface_area(5, 8);
cone.surface_area(6.2, 8.3);
}
main();
Output
Given Radius : 4.3 Slant Height 7
Surface area of cone 152.64998703792804
Given Radius : 5 Slant Height 8
Surface area of cone 204.20352248333654
Given Radius : 6.2 Slant Height 8.3
Surface area of cone 282.4291795577224
# Python 3 Program
# Find the surface area of a cone
import math
class Cone :
# Calculate surface area of a cone by given radius and slant height
def surface_area(self, radius, slant_height) :
print("\nGiven Radius : ", radius ," Slant Height ", slant_height, end = "")
# Calculate surface area of cone
area = math.pi * radius * slant_height + math.pi * (radius * radius)
print("\nSurface area of cone ", area ,"\n", end = "")
def main() :
cone = Cone()
# Simple Case
cone.surface_area(4.3, 7)
cone.surface_area(5, 8)
cone.surface_area(6.2, 8.3)
if __name__ == "__main__": main()
Output
Given Radius : 4.3 Slant Height 7
Surface area of cone 152.64998703792804
Given Radius : 5 Slant Height 8
Surface area of cone 204.20352248333654
Given Radius : 6.2 Slant Height 8.3
Surface area of cone 282.4291795577224
# Ruby Program
# Find the surface area of a cone
class Cone
# Calculate surface area of a cone by given radius and slant height
def surface_area(radius, slant_height)
# Formula of cone area
# π * r * s + π * r²
# here r is radius
# s is slant_height
# Display given inputs
print("\nGiven Radius : ", radius ," Slant Height ", slant_height)
# Calculate surface area of cone
area = Math::PI * radius * slant_height + Math::PI * (radius * radius)
# Display surface area
print("\nSurface area of cone ", area ,"\n")
end
end
def main()
cone = Cone.new()
# Simple Case
cone.surface_area(4.3, 7)
cone.surface_area(5, 8)
cone.surface_area(6.2, 8.3)
end
main()
Output
Given Radius : 4.3 Slant Height 7
Surface area of cone 152.64998703792804
Given Radius : 5 Slant Height 8
Surface area of cone 204.20352248333654
Given Radius : 6.2 Slant Height 8.3
Surface area of cone 282.4291795577224
// Scala Program
// Find the surface area of a cone
class Cone
{
//Calculate surface area of a cone by given radius and slant height
def surface_area(radius: Double, slant_height: Double): Unit = {
// Formula of cone area
// π * r * s + π * r²
// here r is radius
// s is slant_height
//Display given inputs
print("\nGiven Radius : " + radius + " Slant Height " + slant_height);
//Calculate surface area of cone
var area: Double = Math.PI * radius * slant_height + Math.PI * (radius * radius);
//Display surface area
print("\nSurface area of cone " + area + "\n");
}
}
object Main
{
def main(args: Array[String]): Unit = {
var cone: Cone = new Cone();
//Simple Case
cone.surface_area(4.3, 7);
cone.surface_area(5, 8);
cone.surface_area(6.2, 8.3);
}
}
Output
Given Radius : 4.3 Slant Height 7.0
Surface area of cone 152.64998703792804
Given Radius : 5.0 Slant Height 8.0
Surface area of cone 204.20352248333654
Given Radius : 6.2 Slant Height 8.3
Surface area of cone 282.4291795577224
// Swift Program
// Find the surface area of a cone
import Foundation
class Cone
{
//Calculate surface area of a cone by given radius and slant height
func surface_area(_ radius: Double, _ slant_height: Double)
{
print("\nGiven Radius : ", radius ," Slant Height ", slant_height, terminator: "");
//Calculate surface area of cone
let area: Double = Double.pi * radius * slant_height + Double.pi * (radius * radius);
print("\nSurface area of cone ", area ,"\n", terminator: "");
}
}
func main()
{
let cone: Cone? = Cone();
//Simple Case
cone!.surface_area(4.3, 7);
cone!.surface_area(5, 8);
cone!.surface_area(6.2, 8.3);
}
main();
Output
Given Radius : 4.3 Slant Height 7.0
Surface area of cone 152.649987037928
Given Radius : 5.0 Slant Height 8.0
Surface area of cone 204.203522483337
Given Radius : 6.2 Slant Height 8.3
Surface area of cone 282.429179557722
Output Explanation
The code calculates the surface area for each test case and displays the results. For a cone with a radius of 4.3 and a slant height of 7, the surface area is approximately 152.649987. Similarly, for a radius of 5 with a slant height of 8, the surface area is approximately 204.203522. The third test case also follows the same pattern.
Time Complexity
The time complexity of this code is constant O(1) because the calculations involve basic arithmetic operations and the value of π, which are calculated in constant time regardless of the input size. The program performs a fixed number of operations for each test case, making it efficient.
Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.
New Comment