Find the surface area of Hexagonal Prism
A hexagonal prism is a three-dimensional geometric shape that consists of two parallel hexagonal bases connected by rectangular sides. Finding the surface area of a hexagonal prism involves calculating the total area of all its external faces. This calculation is important in various fields such as architecture, engineering, and manufacturing, where prism-like structures are encountered.
Problem Statement
Given the base length and height of the hexagonal prism, the task is to calculate its surface area. The formula for finding the surface area of a hexagonal prism is:
Surface Area = 6 * base * height + 3 * √3 * base^2
Example Scenario
Imagine you are an engineer designing a storage container with a hexagonal prism shape. You need to determine the total surface area of the container to ensure you have enough material for construction. Calculating the surface area helps you estimate costs and design requirements accurately.
Idea to Solve the Problem
To solve this problem, we can follow these steps:
- Accept the base length and height of the hexagonal prism as inputs.
- Use the formula to calculate the surface area of the hexagonal prism.
- Display the calculated surface area.
Pseudocode
function hexagonal_surface(base, height):
area = 6 * base * height + 3 * √3 * base^2
return area
main:
base1 = 7
height1 = 8
base2 = 5
height2 = 5
base3 = 6
height3 = 5.8
area1 = hexagonal_surface(base1, height1)
area2 = hexagonal_surface(base2, height2)
area3 = hexagonal_surface(base3, height3)
print("Hexagonal Prism Size [ base :", base1, ", height :", height1, "]")
print("Surface Area :", area1)
print("Hexagonal Prism Size [ base :", base2, ", height :", height2, "]")
print("Surface Area :", area2)
print("Hexagonal Prism Size [ base :", base3, ", height :", height3, "]")
print("Surface Area :", area3)
Algorithm Explanation
- Define a function
hexagonal_surface
that takes the base length and height as inputs. - Inside the function, use the provided formula to calculate the surface area of the hexagonal prism.
- In the
main
function, set three test cases with different values for base length and height. - Calculate the surface areas for each test case by calling the
hexagonal_surface
function. - Display the calculated surface areas along with their respective base lengths and heights.
Code Solution
//C Program
//Find the surface area of Hexagonal Prism
#include <stdio.h>
#include <math.h>
//Calculate surface area of hexagonal prism by given base and height
void hexagonal_surface(double base, double height)
{
// Formula
// 6ah + 3√3a²
// Here a is base and h is height
double area = 6 * base * height + 3 * sqrt(3) * base * base;;
//Display result
printf(" Hexagonal Prism Size [ base : %lf, height : %lf] ", base, height);
printf("\n Surface area : %lf\n\n", area);
}
int main()
{
//Test Case
hexagonal_surface(7, 8);
hexagonal_surface(5, 5);
hexagonal_surface(6, 5.8);
return 0;
}
Output
Hexagonal Prism Size [ base : 7.000000, height : 8.000000]
Surface area : 590.611469
Hexagonal Prism Size [ base : 5.000000, height : 5.000000]
Surface area : 279.903811
Hexagonal Prism Size [ base : 6.000000, height : 5.800000]
Surface area : 395.861487
// Java Program
// Find the surface area of Hexagonal Prism
class Hexagonal
{
//Calculate surface area of hexagonal prism by given base and height
public void hexagonal_surface(double base, double height)
{
// Formula
// 6ah + 3√3a²
// Here a is base and h is height
double area = 6 * base * height + 3 * Math.sqrt(3) * base * base;;
//Display result
System.out.print(" Hexagonal Prism Size [ base : " + base + ", height : " + height + "] ");
System.out.print("\n Surface area : " + area + "\n\n");
}
public static void main(String[] args)
{
Hexagonal obj = new Hexagonal();
//Test Case
obj.hexagonal_surface(7, 8);
obj.hexagonal_surface(5, 5);
obj.hexagonal_surface(6, 5.8);
}
}
Output
Hexagonal Prism Size [ base : 7.0, height : 8.0]
Surface area : 590.611468712625
Hexagonal Prism Size [ base : 5.0, height : 5.0]
Surface area : 279.9038105676658
Hexagonal Prism Size [ base : 6.0, height : 5.8]
Surface area : 395.8614872174387
// C++ Program
// Find the surface area of Hexagonal Prism
#include<iostream>
#include <math.h>
using namespace std;
class Hexagonal
{
public:
//Calculate surface area of hexagonal prism by given base and height
void hexagonal_surface(double base, double height)
{
// Formula
// 6ah + 3√3a²
// Here a is base and h is height
double area = 6 *base * height + 3 * sqrt(3) * base * base;;
cout << " Hexagonal Prism Size [ base : " << base << ", height : " << height << "] ";
cout << "\n Surface area : " << area << "\n\n";
}
};
int main()
{
Hexagonal obj;
//Test Case
obj.hexagonal_surface(7, 8);
obj.hexagonal_surface(5, 5);
obj.hexagonal_surface(6, 5.8);
return 0;
}
Output
Hexagonal Prism Size [ base : 7, height : 8]
Surface area : 590.611
Hexagonal Prism Size [ base : 5, height : 5]
Surface area : 279.904
Hexagonal Prism Size [ base : 6, height : 5.8]
Surface area : 395.861
// C# Program
// Find the surface area of Hexagonal Prism
using System;
class Hexagonal
{
//Calculate surface area of hexagonal prism by given base and height
public void hexagonal_surface(double base_size, double height)
{
// Formula
// 6ah + 3√3a²
// Here a is base and h is height
double area = 6 * base_size * height + 3 * Math.Sqrt(3) * base_size * base_size;;
Console.Write(" Hexagonal Prism Size [ base : " + base_size + ", height : " + height + "] ");
Console.Write("\n Surface area : " + area + "\n\n");
}
public static void Main(String[] args)
{
Hexagonal obj = new Hexagonal();
//Test Case
obj.hexagonal_surface(7, 8);
obj.hexagonal_surface(5, 5);
obj.hexagonal_surface(6, 5.8);
}
}
Output
Hexagonal Prism Size [ base : 7, height : 8]
Surface area : 590.611468712625
Hexagonal Prism Size [ base : 5, height : 5]
Surface area : 279.903810567666
Hexagonal Prism Size [ base : 6, height : 5.8]
Surface area : 395.861487217439
<?php
// Php Program
// Find the surface area of Hexagonal Prism
class Hexagonal
{
//Calculate surface area of hexagonal prism by given base and height
public function hexagonal_surface($base, $height)
{
// Formula
// 6ah + 3√3a²
// Here a is base and h is height
$area = 6 * $base * $height + 3 * sqrt(3) * $base * $base;;
//Display result
echo(" Hexagonal Prism Size [ base : ". $base .", height : ". $height ."] ");
echo("\n Surface area : ". $area ."\n\n");
}
}
function main()
{
$obj = new Hexagonal();
//Test Case
$obj->hexagonal_surface(7, 8);
$obj->hexagonal_surface(5, 5);
$obj->hexagonal_surface(6, 5.8);
}
main();
Output
Hexagonal Prism Size [ base : 7, height : 8]
Surface area : 590.61146871262
Hexagonal Prism Size [ base : 5, height : 5]
Surface area : 279.90381056767
Hexagonal Prism Size [ base : 6, height : 5.8]
Surface area : 395.86148721744
// Node Js Program
// Find the surface area of Hexagonal Prism
class Hexagonal
{
//Calculate surface area of hexagonal prism by given base and height
hexagonal_surface(base, height)
{
// Formula
// 6ah + 3√3a²
// Here a is base and h is height
var area = 6 *base *height + 3 *Math.sqrt(3) *base *base;;
//Display result
process.stdout.write(" Hexagonal Prism Size [ base : " + base + ", height : " + height + "] ");
process.stdout.write("\n Surface area : " + area + "\n\n");
}
}
function main(args)
{
var obj = new Hexagonal();
//Test Case
obj.hexagonal_surface(7, 8);
obj.hexagonal_surface(5, 5);
obj.hexagonal_surface(6, 5.8);
}
main();
Output
Hexagonal Prism Size [ base : 7, height : 8]
Surface area : 590.611468712625
Hexagonal Prism Size [ base : 5, height : 5]
Surface area : 279.9038105676658
Hexagonal Prism Size [ base : 6, height : 5.8]
Surface area : 395.8614872174387
# Python 3 Program
# Find the surface area of Hexagonal Prism
import math
class Hexagonal :
# Calculate surface area of hexagonal prism by given base and height
def hexagonal_surface(self, base, height) :
# Formula
# 6ah + 3√3a²
# Here a is base and h is height
area = 6 * base * height + 3 * math.sqrt(3) * base * base
# Display result
print(" Hexagonal Prism Size [ base : ", base ,", height : ", height ,"] ", end = "")
print("\n Surface area : ", area ,"\n\n", end = "")
def main() :
obj = Hexagonal()
# Test Case
obj.hexagonal_surface(7, 8)
obj.hexagonal_surface(5, 5)
obj.hexagonal_surface(6, 5.8)
if __name__ == "__main__": main()
Output
Hexagonal Prism Size [ base : 7 , height : 8 ]
Surface area : 590.611468712625
Hexagonal Prism Size [ base : 5 , height : 5 ]
Surface area : 279.9038105676658
Hexagonal Prism Size [ base : 6 , height : 5.8 ]
Surface area : 395.8614872174387
# Ruby Program
# Find the surface area of Hexagonal Prism
class Hexagonal
# Calculate surface area of hexagonal prism by given base and height
def hexagonal_surface(base, height)
# Formula
# 6ah + 3√3a²
# Here a is base and h is height
area = 6 * base * height + 3 * Math.sqrt(3) * base * base
# Display result
print(" Hexagonal Prism Size [ base : ", base ,", height : ", height ,"] ")
print("\n Surface area : ", area ,"\n\n")
end
end
def main()
obj = Hexagonal.new()
# Test Case
obj.hexagonal_surface(7, 8)
obj.hexagonal_surface(5, 5)
obj.hexagonal_surface(6, 5.8)
end
main()
Output
Hexagonal Prism Size [ base : 7, height : 8]
Surface area : 590.611468712625
Hexagonal Prism Size [ base : 5, height : 5]
Surface area : 279.9038105676658
Hexagonal Prism Size [ base : 6, height : 5.8]
Surface area : 395.8614872174387
// Scala Program
// Find the surface area of Hexagonal Prism
class Hexagonal
{
//Calculate surface area of hexagonal prism by given base and height
def hexagonal_surface(base: Double, height: Double): Unit = {
// Formula
// 6ah + 3√3a²
// Here a is base and h is height
var area: Double = 6 * base * height + 3 * Math.sqrt(3) * base * base;
//Display result
print(" Hexagonal Prism Size [ base : " + base + ", height : " + height + "] ");
print("\n Surface area : " + area + "\n\n");
}
}
object Main
{
def main(args: Array[String]): Unit = {
var obj: Hexagonal = new Hexagonal();
//Test Case
obj.hexagonal_surface(7, 8);
obj.hexagonal_surface(5, 5);
obj.hexagonal_surface(6, 5.8);
}
}
Output
Hexagonal Prism Size [ base : 7.0, height : 8.0]
Surface area : 590.611468712625
Hexagonal Prism Size [ base : 5.0, height : 5.0]
Surface area : 279.9038105676658
Hexagonal Prism Size [ base : 6.0, height : 5.8]
Surface area : 395.8614872174387
// Swift Program
// Find the surface area of Hexagonal Prism
import Foundation
class Hexagonal
{
//Calculate surface area of hexagonal prism by given base and height
func hexagonal_surface(_ base: Double, _ height: Double)
{
// Formula
// 6ah + 3√3a²
// Here a is base and h is height
let area: Double = 6 * base * height + 3 * sqrt(3) * base * base;
//Display result
print(" Hexagonal Prism Size [ base : ", base ,", height : ", height ,"] ", terminator: "");
print("\n Surface area : ", area ,"\n\n", terminator: "");
}
}
func main()
{
let obj: Hexagonal = Hexagonal();
//Test Case
obj.hexagonal_surface(7, 8);
obj.hexagonal_surface(5, 5);
obj.hexagonal_surface(6, 5.8);
}
main();
Output
Hexagonal Prism Size [ base : 7.0 , height : 8.0 ]
Surface area : 590.611468712625
Hexagonal Prism Size [ base : 5.0 , height : 5.0 ]
Surface area : 279.903810567666
Hexagonal Prism Size [ base : 6.0 , height : 5.8 ]
Surface area : 395.861487217439
Output Explanation
The code calculates the surface area for each test case and displays the results. For a hexagonal prism with a base length of 7 and a height of 8, the surface area is approximately 590.611469. Similarly, for base lengths of 5 and 6 with heights of 5 and 5.8, the surface areas are approximately 279.903811 and 395.861487, respectively.
Time Complexity
The time complexity of this code is constant O(1) because the calculations involve basic arithmetic operations and square root calculation, which take a constant amount of 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