Calculate area of trapezoid

Here given code implementation process.

// C Program
// Calculate area of trapezoid
#include <stdio.h>

//Calculate area of trapezoid by given bases and altitude
void trapezoid_area(double base1, double base2, double altitude)
{
	//Calculate area of trapezoid
	double area = ((base1 + base2) / 2) * altitude;
	//Display the result of trapezoid area
	printf(" Trapezoid Size [ base1 : %lf, base2 : %lf, altitude : %lf ] ", base1, base2, altitude);
	printf("\n Trapezoid Area : %lf\n\n", area);
}
int main()
{
	//Test Cases  
	trapezoid_area(24, 9.3, 8);
	trapezoid_area(20, 15, 32);
	trapezoid_area(5.6, 9.2, 4.2);
	return 0;
}

Output

 Trapezoid Size [ base1 : 24.000000, base2 : 9.300000, altitude : 8.000000 ]
 Trapezoid Area : 133.200000

 Trapezoid Size [ base1 : 20.000000, base2 : 15.000000, altitude : 32.000000 ]
 Trapezoid Area : 560.000000

 Trapezoid Size [ base1 : 5.600000, base2 : 9.200000, altitude : 4.200000 ]
 Trapezoid Area : 31.080000
/*
  C++ program
  Find area of trapezoid
*/
#include<iostream>

using namespace std;
class TrapezoidArea
{
	public:
		//Calculate area of trapezoid by given bases and altitude
		void trapezoid_area(double base1, double base2, double altitude)
		{
			//Calculate area of trapezoid
			double area = ((base1 + base2) / 2) *altitude;
			cout << " Trapezoid Size [ base1 : " << base1 << ", base2 : " << base2 << ", altitude : " << altitude << " ] ";
			cout << "\n Trapezoid Area : " << area << "\n\n";
		}
};
int main()
{
	TrapezoidArea obj =  TrapezoidArea();
	//Test Cases  
	obj.trapezoid_area(24, 9.3, 8);
	obj.trapezoid_area(20, 15, 32);
	obj.trapezoid_area(5.6, 9.2, 4.2);
	return 0;
}

Output

 Trapezoid Size [ base1 : 24, base2 : 9.3, altitude : 8 ]
 Trapezoid Area : 133.2

 Trapezoid Size [ base1 : 20, base2 : 15, altitude : 32 ]
 Trapezoid Area : 560

 Trapezoid Size [ base1 : 5.6, base2 : 9.2, altitude : 4.2 ]
 Trapezoid Area : 31.08
/*
  Java program
  Find area of trapezoid
*/
public class TrapezoidArea
{
	//Calculate area of trapezoid by given bases and altitude
	public void trapezoid_area(double base1, double base2, double altitude)
	{
		//Calculate area of trapezoid
		double area = ((base1 + base2) / 2) * altitude;
		//Display the result of trapezoid area
		System.out.print(" Trapezoid Size [ base1 : " + base1 + ", base2 : " + base2 + ", altitude : " + altitude + " ] ");
		System.out.print("\n Trapezoid Area : " + area + "\n\n");
	}
	public static void main(String[] args)
	{
		TrapezoidArea obj = new TrapezoidArea();
		//Test Cases  
		obj.trapezoid_area(24, 9.3, 8);
		obj.trapezoid_area(20, 15, 32);
		obj.trapezoid_area(5.6, 9.2, 4.2);
	}
}

Output

 Trapezoid Size [ base1 : 24.0, base2 : 9.3, altitude : 8.0 ] 
 Trapezoid Area : 133.2

 Trapezoid Size [ base1 : 20.0, base2 : 15.0, altitude : 32.0 ] 
 Trapezoid Area : 560.0

 Trapezoid Size [ base1 : 5.6, base2 : 9.2, altitude : 4.2 ] 
 Trapezoid Area : 31.08

/*
  C# program
  Find area of trapezoid
*/
using System;
public class TrapezoidArea
{
	//Calculate area of trapezoid by given bases and altitude
	public void trapezoid_area(double base1, double base2, double altitude)
	{
		//Calculate area of trapezoid
		double area = ((base1 + base2) / 2) * altitude;
		Console.Write(" Trapezoid Size [ base1 : " + base1 + ", base2 : " + base2 + ", altitude : " + altitude + " ] ");
		Console.Write("\n Trapezoid Area : " + area + "\n\n");
	}
	public static void Main(String[] args)
	{
		TrapezoidArea obj = new TrapezoidArea();
		//Test Cases  
		obj.trapezoid_area(24, 9.3, 8);
		obj.trapezoid_area(20, 15, 32);
		obj.trapezoid_area(5.6, 9.2, 4.2);
	}
}

Output

 Trapezoid Size [ base1 : 24, base2 : 9.3, altitude : 8 ]
 Trapezoid Area : 133.2

 Trapezoid Size [ base1 : 20, base2 : 15, altitude : 32 ]
 Trapezoid Area : 560

 Trapezoid Size [ base1 : 5.6, base2 : 9.2, altitude : 4.2 ]
 Trapezoid Area : 31.08
<?php
/*
  Php program
  Find area of trapezoid
*/
class TrapezoidArea
{
	//Calculate area of trapezoid by given bases and altitude
	public 	function trapezoid_area($base1, $base2, $altitude)
	{
		//Calculate area of trapezoid
		$area = (($base1 + $base2) / 2) *$altitude;
		//Display the result of trapezoid area
		echo(" Trapezoid Size [ base1 : ". $base1 .", base2 : ". $base2 .", altitude : ". $altitude ." ] ");
		echo("\n Trapezoid Area : ". $area ."\n\n");
	}
}

function main()
{
	$obj = new TrapezoidArea();
	//Test Cases  
	$obj->trapezoid_area(24, 9.3, 8);
	$obj->trapezoid_area(20, 15, 32);
	$obj->trapezoid_area(5.6, 9.2, 4.2);
}
main();

Output

 Trapezoid Size [ base1 : 24, base2 : 9.3, altitude : 8 ]
 Trapezoid Area : 133.2

 Trapezoid Size [ base1 : 20, base2 : 15, altitude : 32 ]
 Trapezoid Area : 560

 Trapezoid Size [ base1 : 5.6, base2 : 9.2, altitude : 4.2 ]
 Trapezoid Area : 31.08
/*
  Node Js program
  Find area of trapezoid
*/
class TrapezoidArea
{
	//Calculate area of trapezoid by given bases and altitude
	trapezoid_area(base1, base2, altitude)
	{
		//Calculate area of trapezoid
		var area = ((base1 + base2) / 2) *altitude;
		//Display the result of trapezoid area
		process.stdout.write(" Trapezoid Size [ base1 : " + base1 + ", base2 : " + base2 + ", altitude : " + altitude + " ] ");
		process.stdout.write("\n Trapezoid Area : " + area + "\n\n");
	}
}

function main(args)
{
	var obj = new TrapezoidArea();
	//Test Cases  
	obj.trapezoid_area(24, 9.3, 8);
	obj.trapezoid_area(20, 15, 32);
	obj.trapezoid_area(5.6, 9.2, 4.2);
}
main();

Output

 Trapezoid Size [ base1 : 24, base2 : 9.3, altitude : 8 ]
 Trapezoid Area : 133.2

 Trapezoid Size [ base1 : 20, base2 : 15, altitude : 32 ]
 Trapezoid Area : 560

 Trapezoid Size [ base1 : 5.6, base2 : 9.2, altitude : 4.2 ]
 Trapezoid Area : 31.08
#   Python 3 program
#   Find area of trapezoid

class TrapezoidArea :
	# Calculate area of trapezoid by given bases and altitude
	def trapezoid_area(self, base1, base2, altitude) :
		# Calculate area of trapezoid
		area = ((base1 + base2) / 2) * altitude
		
		# Display the result of trapezoid area
		print(" Trapezoid Size [ base1 : ", base1 ,", base2 : ", base2 ,", altitude : ", altitude ," ] ", end = "")
		print("\n Trapezoid Area : ", area ,"\n\n", end = "")
	

def main() :
	obj = TrapezoidArea()
	# Test Cases  
	obj.trapezoid_area(24, 9.3, 8)
	obj.trapezoid_area(20, 15, 32)
	obj.trapezoid_area(5.6, 9.2, 4.2)


if __name__ == "__main__": main()

Output

 Trapezoid Size [ base1 :  24 , base2 :  9.3 , altitude :  8  ]
 Trapezoid Area :  133.2

 Trapezoid Size [ base1 :  20 , base2 :  15 , altitude :  32  ]
 Trapezoid Area :  560.0

 Trapezoid Size [ base1 :  5.6 , base2 :  9.2 , altitude :  4.2  ]
 Trapezoid Area :  31.08
#   Ruby program
#   Find area of trapezoid

class TrapezoidArea

	# Calculate area of trapezoid by given bases and altitude
	def trapezoid_area(base1, base2, altitude)
	
		# Calculate area of trapezoid
		area = ((base1 + base2) / 2) * altitude
		# Display the result of trapezoid area
		print(" Trapezoid Size [ base1  : ", base1 ,", base2  : ", base2 ,", altitude  : ", altitude ," ] ")
		print("\n Trapezoid Area  :", area ,"\n\n")
	end
end
def main()

	obj = TrapezoidArea.new()
	# Test Cases  
	obj.trapezoid_area(24, 9.3, 8)
	obj.trapezoid_area(20, 15, 32)
	obj.trapezoid_area(5.6, 9.2, 4.2)
end
main()

Output

 Trapezoid Size [ base1  : 24, base2  : 9.3, altitude  : 8 ] 
 Trapezoid Area  :133.2

 Trapezoid Size [ base1  : 20, base2  : 15, altitude  : 32 ] 
 Trapezoid Area  :544

 Trapezoid Size [ base1  : 5.6, base2  : 9.2, altitude  : 4.2 ] 
 Trapezoid Area  :31.08

/*
  Scala program
  Find area of trapezoid
*/
class TrapezoidArea
{
	//Calculate area of trapezoid by given bases and altitude
	def trapezoid_area(base1: Double, base2: Double, altitude: Double): Unit = {
		//Calculate area of trapezoid
		var area: Double = ((base1 + base2) / 2) * altitude;
		//Display the result of trapezoid area
		print(" Trapezoid Size [ base1 : " + base1 + ", base2 : " + base2 + ", altitude : " + altitude + " ] ");
		print("\n Trapezoid Area : " + area + "\n\n");
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var obj: TrapezoidArea = new TrapezoidArea();
		//Test Cases  
		obj.trapezoid_area(24, 9.3, 8);
		obj.trapezoid_area(20, 15, 32);
		obj.trapezoid_area(5.6, 9.2, 4.2);
	}
}

Output

 Trapezoid Size [ base1 : 24.0, base2 : 9.3, altitude : 8.0 ]
 Trapezoid Area : 133.2

 Trapezoid Size [ base1 : 20.0, base2 : 15.0, altitude : 32.0 ]
 Trapezoid Area : 560.0

 Trapezoid Size [ base1 : 5.6, base2 : 9.2, altitude : 4.2 ]
 Trapezoid Area : 31.08
/*
  Swift program
  Find area of trapezoid
*/
class TrapezoidArea
{
	//Calculate area of trapezoid by given bases and altitude
	func trapezoid_area(_ base1: Double, _ base2: Double, _ altitude: Double)
	{
		//Calculate area of trapezoid
		let area: Double = ((base1 + base2) / 2) * altitude;
		
		//Display the result of trapezoid area
		print(" Trapezoid Size [ base1 : ", base1 ,", base2 : ", base2 ,", altitude : ", altitude ," ] ", terminator: "");
		print("\n Trapezoid Area : ", area ,"\n\n", terminator: "");
	}
}
func main()
{
	let obj: TrapezoidArea = TrapezoidArea();
	//Test Cases  
	obj.trapezoid_area(24, 9.3, 8);
	obj.trapezoid_area(20, 15, 32);
	obj.trapezoid_area(5.6, 9.2, 4.2);
}
main();

Output

 Trapezoid Size [ base1 :  24.0 , base2 :  9.3 , altitude :  8.0  ]
 Trapezoid Area :  133.2

 Trapezoid Size [ base1 :  20.0 , base2 :  15.0 , altitude :  32.0  ]
 Trapezoid Area :  560.0

 Trapezoid Size [ base1 :  5.6 , base2 :  9.2 , altitude :  4.2  ]
 Trapezoid Area :  31.08


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