Find the volume of cube

Here given code implementation process.

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

//Calculate volume of cube by given edge
void cube_volume(double edge)
{
	// Formula
	// a³  here a is edge
	// edge * edge * edge
	double volume = edge * edge * edge;
	//Display result
	printf(" Cube Size [ edge : %lf] ", edge);
	printf("\n Volume : %lf\n\n", volume);
}
int main()
{
	//Test Case
	cube_volume(7.2);
	cube_volume(9);
	cube_volume(4);
	cube_volume(4.7);
	return 0;
}

Output

 Cube Size [ edge : 7.200000]
 Volume : 373.248000

 Cube Size [ edge : 9.000000]
 Volume : 729.000000

 Cube Size [ edge : 4.000000]
 Volume : 64.000000

 Cube Size [ edge : 4.700000]
 Volume : 103.823000
// Java Program
// Find the volume of cube
class Cube
{
	//Calculate volume of cube by given edge
	public void cube_volume(double edge)
	{
		// Formula
		// a³  here a is edge
		// edge * edge * edge
		double volume = edge * edge * edge;
		//Display result
		System.out.print(" Cube Size [ edge : " + edge + "] ");
		System.out.print("\n Volume  : " + volume + "\n\n");
	}
	public static void main(String[] args)
	{
		Cube obj = new Cube();
		//Test Case
		obj.cube_volume(7.2);
		obj.cube_volume(9);
		obj.cube_volume(4);
		obj.cube_volume(4.7);
	}
}

Output

 Cube Size [ edge : 7.2]
 Volume  : 373.24800000000005

 Cube Size [ edge : 9.0]
 Volume  : 729.0

 Cube Size [ edge : 4.0]
 Volume  : 64.0

 Cube Size [ edge : 4.7]
 Volume  : 103.82300000000002
// C++ Program
// Find the volume of cube
#include<iostream>

using namespace std;
class Cube
{
	public:
		//Calculate volume of cube by given edge
		void cube_volume(double edge)
		{
			// Formula
			// a³  here a is edge
			// edge *edge *edge
			double volume = edge *edge *edge;
			cout << " Cube Size [ edge : " << edge << "] ";
			cout << "\n Volume : " << volume << "\n\n";
		}
};
int main()
{
	Cube obj = Cube();
	//Test Case
	obj.cube_volume(7.2);
	obj.cube_volume(9);
	obj.cube_volume(4);
	obj.cube_volume(4.7);
	return 0;
}

Output

 Cube Size [ edge : 7.2]
 Volume : 373.248

 Cube Size [ edge : 9]
 Volume : 729

 Cube Size [ edge : 4]
 Volume : 64

 Cube Size [ edge : 4.7]
 Volume : 103.823
// C# Program
// Find the volume of cube
using System;
class Cube
{
	//Calculate volume of cube by given edge
	public void cube_volume(double edge)
	{
		// Formula
		// a³  here a is edge
		// edge * edge * edge
		double volume = edge * edge * edge;
		Console.Write(" Cube Size [ edge : " + edge + "] ");
		Console.Write("\n Volume : " + volume + "\n\n");
	}
	public static void Main(String[] args)
	{
		Cube obj = new Cube();
		//Test Case
		obj.cube_volume(7.2);
		obj.cube_volume(9);
		obj.cube_volume(4);
		obj.cube_volume(4.7);
	}
}

Output

 Cube Size [ edge : 7.2]
 Volume : 373.248

 Cube Size [ edge : 9]
 Volume : 729

 Cube Size [ edge : 4]
 Volume : 64

 Cube Size [ edge : 4.7]
 Volume : 103.823
<?php
// Php Program
// Find the volume of cube
class Cube
{
	//Calculate volume of cube by given edge
	public 	function cube_volume($edge)
	{
		// Formula
		// a³  here a is edge
		// edge *edge *edge
		$volume = $edge *$edge *$edge;
		//Display result
		echo(" Cube Size [ edge : ". $edge ."] ");
		echo("\n Volume : ". $volume ."\n\n");
	}
}

function main()
{
	$obj = new Cube();
	//Test Case
	$obj->cube_volume(7.2);
	$obj->cube_volume(9);
	$obj->cube_volume(4);
	$obj->cube_volume(4.7);
}
main();

Output

 Cube Size [ edge : 7.2]
 Volume : 373.248

 Cube Size [ edge : 9]
 Volume : 729

 Cube Size [ edge : 4]
 Volume : 64

 Cube Size [ edge : 4.7]
 Volume : 103.823
// Node Js Program
// Find the volume of cube
class Cube
{
	//Calculate volume of cube by given edge
	cube_volume(edge)
	{
		// Formula
		// a³  here a is edge
		// edge *edge *edge
		var volume = edge *edge *edge;
		//Display result
		process.stdout.write(" Cube Size [ edge : " + edge + "] ");
		process.stdout.write("\n Volume : " + volume + "\n\n");
	}
}

function main(args)
{
	var obj = new Cube();
	//Test Case
	obj.cube_volume(7.2);
	obj.cube_volume(9);
	obj.cube_volume(4);
	obj.cube_volume(4.7);
}
main();

Output

 Cube Size [ edge : 7.2]
 Volume : 373.24800000000005

 Cube Size [ edge : 9]
 Volume : 729

 Cube Size [ edge : 4]
 Volume : 64

 Cube Size [ edge : 4.7]
 Volume : 103.82300000000002
#  Python 3 Program
#  Find the volume of cube
class Cube :
	# Calculate volume of cube by given edge
	def cube_volume(self, edge) :
		#  Formula
		#  a³  here a is edge
		#  edge * edge * edge
		volume = edge * edge * edge
		# Display result
		print(" Cube Size [ edge : ", edge ,"] ")
		print(" Volume : ", volume ,"\n")
	

def main() :
	obj = Cube()
	# Test Case
	obj.cube_volume(7.2)
	obj.cube_volume(9)
	obj.cube_volume(4)
	obj.cube_volume(4.7)


if __name__ == "__main__": main()

Output

 Cube Size [ edge :  7.2 ]
 Volume :  373.24800000000005

 Cube Size [ edge :  9 ]
 Volume :  729

 Cube Size [ edge :  4 ]
 Volume :  64

 Cube Size [ edge :  4.7 ]
 Volume :  103.82300000000002
#  Ruby Program
#  Find the volume of cube
class Cube

	# Calculate volume of cube by given edge
	def cube_volume(edge)
	
		#  Formula
		#  a³  here a is edge
		#  edge * edge * edge
		volume = edge * edge * edge
		# Display result
		print(" Cube Size [ edge  : ", edge ,"] ")
		print("\n Volume  : ", volume ,"\n\n")
	end
end
def main()

	obj = Cube.new()
	# Test Case
	obj.cube_volume(7.2)
	obj.cube_volume(9)
	obj.cube_volume(4)
	obj.cube_volume(4.7)
end
main()

Output

 Cube Size [ edge  : 7.2] 
 Volume  : 373.24800000000005

 Cube Size [ edge  : 9] 
 Volume  : 729

 Cube Size [ edge  : 4] 
 Volume  : 64

 Cube Size [ edge  : 4.7] 
 Volume  : 103.82300000000002

// Scala Program
// Find the volume of cube
class Cube
{
	//Calculate volume of cube by given edge
	def cube_volume(edge: Double): Unit = {
		// Formula
		// a³  here a is edge
		// edge * edge * edge
		var volume: Double = edge * edge * edge;
		//Display result
		print(" Cube Size [ edge : " + edge + "] ");
		print("\n Volume : " + volume + "\n\n");
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var obj: Cube = new Cube();
		//Test Case
		obj.cube_volume(7.2);
		obj.cube_volume(9);
		obj.cube_volume(4);
		obj.cube_volume(4.7);
	}
}

Output

 Cube Size [ edge : 7.2]
 Volume : 373.24800000000005

 Cube Size [ edge : 9.0]
 Volume : 729.0

 Cube Size [ edge : 4.0]
 Volume : 64.0

 Cube Size [ edge : 4.7]
 Volume : 103.82300000000002
// Swift Program
// Find the volume of cube
class Cube
{
	//Calculate volume of cube by given edge
	func cube_volume(_ edge: Double)
	{
		// Formula
		// a³  here a is edge
		// edge * edge * edge
		let volume: Double = edge * edge * edge;
		//Display result
		print(" Cube Size [ edge : ", edge ,"] ");
		print(" Volume : ", volume ,"\n");
	}
}
func main()
{
	let obj: Cube = Cube();
	//Test Case
	obj.cube_volume(7.2);
	obj.cube_volume(9);
	obj.cube_volume(4);
	obj.cube_volume(4.7);
}
main();

Output

 Cube Size [ edge :  7.2 ]
 Volume :  373.248

 Cube Size [ edge :  9.0 ]
 Volume :  729.0

 Cube Size [ edge :  4.0 ]
 Volume :  64.0

 Cube Size [ edge :  4.7 ]
 Volume :  103.823


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