Find the surface area of cube

Here given code implementation process.

//C Program
//Find the surface area of cube
#include <stdio.h>

//Calculate surface area of cube by given edge
void cube_surface_area(double edge)
{
	// Formula
	// 6 * edge * edge
	double area = 6 * edge * edge;
	//Display result
	printf(" Cube Size [ edge : %lf] ", edge);
	printf("\n Surface Area : %lf\n\n", area);
}
int main()
{
	//Test Case
	cube_surface_area(7);
	cube_surface_area(15);
	cube_surface_area(4);
	cube_surface_area(4.7);
	return 0;
}

Output

 Cube Size [ edge : 7.000000]
 Surface Area : 294.000000

 Cube Size [ edge : 15.000000]
 Surface Area : 1350.000000

 Cube Size [ edge : 4.000000]
 Surface Area : 96.000000

 Cube Size [ edge : 4.700000]
 Surface Area : 132.540000
// Java Program
// Find the surface area of cube
class Cube
{
	//Calculate surface area of cube by given edge
	public void cube_surface_area(double edge)
	{
		// Formula
		// 6 * edge * edge
		double area = 6 * edge * edge;
		//Display result
		System.out.print(" Cube Size [ edge : " + edge + "] ");
		System.out.print("\n Surface Area : " + area + "\n\n");
	}
	public static void main(String[] args)
	{
		Cube obj = new Cube();
		//Test Case
		obj.cube_surface_area(7);
		obj.cube_surface_area(15);
		obj.cube_surface_area(4);
		obj.cube_surface_area(4.7);
	}
}

Output

 Cube Size [ edge : 7.0]
 Surface Area : 294.0

 Cube Size [ edge : 15.0]
 Surface Area : 1350.0

 Cube Size [ edge : 4.0]
 Surface Area : 96.0

 Cube Size [ edge : 4.7]
 Surface Area : 132.54000000000002
// C++ Program
// Find the surface area of cube
#include<iostream>

using namespace std;
class Cube
{
	public:
		//Calculate surface area of cube by given edge
		void cube_surface_area(double edge)
		{
			// Formula
			// 6 *edge *edge
			double area = 6 *edge *edge;
			cout << " Cube Size [ edge : " << edge << "] ";
			cout << "\n Surface Area : " << area << "\n\n";
		}
};
int main()
{
	Cube obj ;
	//Test Case
	obj.cube_surface_area(7);
	obj.cube_surface_area(15);
	obj.cube_surface_area(4);
	obj.cube_surface_area(4.7);
	return 0;
}

Output

 Cube Size [ edge : 7]
 Surface Area : 294

 Cube Size [ edge : 15]
 Surface Area : 1350

 Cube Size [ edge : 4]
 Surface Area : 96

 Cube Size [ edge : 4.7]
 Surface Area : 132.54
// C# Program
// Find the surface area of cube
using System;
class Cube
{
	//Calculate surface area of cube by given edge
	public void cube_surface_area(double edge)
	{
		// Formula
		// 6 * edge * edge
		double area = 6 * edge * edge;
		Console.Write(" Cube Size [ edge : " + edge + "] ");
		Console.Write("\n Surface Area : " + area + "\n\n");
	}
	public static void Main(String[] args)
	{
		Cube obj = new Cube();
		//Test Case
		obj.cube_surface_area(7);
		obj.cube_surface_area(15);
		obj.cube_surface_area(4);
		obj.cube_surface_area(4.7);
	}
}

Output

 Cube Size [ edge : 7]
 Surface Area : 294

 Cube Size [ edge : 15]
 Surface Area : 1350

 Cube Size [ edge : 4]
 Surface Area : 96

 Cube Size [ edge : 4.7]
 Surface Area : 132.54
<?php
// Php Program
// Find the surface area of cube
class Cube
{
	//Calculate surface area of cube by given edge
	public 	function cube_surface_area($edge)
	{
		// Formula
		// 6 *edge *edge
		$area = 6 *$edge *$edge;
		//Display result
		echo(" Cube Size [ edge : ". $edge ."] ");
		echo("\n Surface Area : ". $area ."\n\n");
	}
}

function main()
{
	$obj = new Cube();
	//Test Case
	$obj->cube_surface_area(7);
	$obj->cube_surface_area(15);
	$obj->cube_surface_area(4);
	$obj->cube_surface_area(4.7);
}
main();

Output

 Cube Size [ edge : 7]
 Surface Area : 294

 Cube Size [ edge : 15]
 Surface Area : 1350

 Cube Size [ edge : 4]
 Surface Area : 96

 Cube Size [ edge : 4.7]
 Surface Area : 132.54
// Node Js Program
// Find the surface area of cube
class Cube
{
	//Calculate surface area of cube by given edge
	cube_surface_area(edge)
	{
		// Formula
		// 6 *edge *edge
		var area = 6 *edge *edge;
		//Display result
		process.stdout.write(" Cube Size [ edge : " + edge + "] ");
		process.stdout.write("\n Surface Area : " + area + "\n\n");
	}
}

function main(args)
{
	var obj = new Cube();
	//Test Case
	obj.cube_surface_area(7);
	obj.cube_surface_area(15);
	obj.cube_surface_area(4);
	obj.cube_surface_area(4.7);
}
main();

Output

 Cube Size [ edge : 7]
 Surface Area : 294

 Cube Size [ edge : 15]
 Surface Area : 1350

 Cube Size [ edge : 4]
 Surface Area : 96

 Cube Size [ edge : 4.7]
 Surface Area : 132.54000000000002
#  Python 3 Program
#  Find the surface area of cube
class Cube :
	# Calculate surface area of cube by given edge
	def cube_surface_area(self, edge) :
		#  Formula
		#  6 * edge * edge
		area = 6 * edge * edge
		# Display result
		print(" Cube Size [ edge : ", edge , end = "] ")
		print("\n Surface Area : ", area ,"\n")
	

def main() :
	obj = Cube()
	# Test Case
	obj.cube_surface_area(7)
	obj.cube_surface_area(15)
	obj.cube_surface_area(4)
	obj.cube_surface_area(4.7)


if __name__ == "__main__": main()

Output

 Cube Size [ edge :  7]
 Surface Area :  294

 Cube Size [ edge :  15]
 Surface Area :  1350

 Cube Size [ edge :  4]
 Surface Area :  96

 Cube Size [ edge :  4.7]
 Surface Area :  132.54000000000002
#  Ruby Program
#  Find the surface area of cube
class Cube

	# Calculate surface area of cube by given edge
	def cube_surface_area(edge)
	
		#  Formula
		#  6 * edge * edge
		area = 6 * edge * edge
		# Display result
		print(" Cube Size [ edge  : ", edge ,"] ")
		print("\n Surface Area  : ", area ,"\n\n")
	end
end
def main()

	obj = Cube.new()
	# Test Case
	obj.cube_surface_area(7)
	obj.cube_surface_area(15)
	obj.cube_surface_area(4)
	obj.cube_surface_area(4.7)
end
main()

Output

 Cube Size [ edge  : 7] 
 Surface Area  : 294

 Cube Size [ edge  : 15] 
 Surface Area  : 1350

 Cube Size [ edge  : 4] 
 Surface Area  : 96

 Cube Size [ edge  : 4.7] 
 Surface Area  : 132.54000000000002

// Scala Program
// Find the surface area of cube
class Cube
{
	//Calculate surface area of cube by given edge
	def cube_surface_area(edge: Double): Unit = {
		// Formula
		// 6 * edge * edge
		var area: Double = 6 * edge * edge;
		//Display result
		print(" Cube Size [ edge : " + edge + "] ");
		print("\n Surface Area : " + area + "\n\n");
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var obj: Cube = new Cube();
		//Test Case
		obj.cube_surface_area(7);
		obj.cube_surface_area(15);
		obj.cube_surface_area(4);
		obj.cube_surface_area(4.7);
	}
}

Output

 Cube Size [ edge : 7.0]
 Surface Area : 294.0

 Cube Size [ edge : 15.0]
 Surface Area : 1350.0

 Cube Size [ edge : 4.0]
 Surface Area : 96.0

 Cube Size [ edge : 4.7]
 Surface Area : 132.54000000000002
// Swift Program
// Find the surface area of cube
class Cube
{
	//Calculate surface area of cube by given edge
	func cube_surface_area(_ edge: Double)
	{
		// Formula
		// 6 * edge * edge
		let area: Double = 6 * edge * edge;
		//Display result
		print(" Cube Size [ edge : ", edge , terminator: " ]");
		print("\n Surface Area : ", area ,"\n");
	}
}
func main()
{
	let obj: Cube = Cube();
	//Test Case
	obj.cube_surface_area(7);
	obj.cube_surface_area(15);
	obj.cube_surface_area(4);
	obj.cube_surface_area(4.7);
}
main();

Output

 Cube Size [ edge :  7.0 ]
 Surface Area :  294.0

 Cube Size [ edge :  15.0 ]
 Surface Area :  1350.0

 Cube Size [ edge :  4.0 ]
 Surface Area :  96.0

 Cube Size [ edge :  4.7 ]
 Surface Area :  132.54


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







© 2021, kalkicode.com, All rights reserved