Calculate area of rectangle

Here given code implementation process.

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

//Calculate area of rectangle by given width and height
void rectangle_area(double width, double height)
{
  //Calculate area of rectangle
  double area = width * height;
  //Display the result of rectangle area
  printf(" Rectangle Size [ width : %lf, height : %lf ] ", width, height);
  printf("\n Rectangle Area : %lf\n\n", area);
}
int main()
{
  //Test Cases  
  rectangle_area(10, 20);
  rectangle_area(15.5, 13.4);
  rectangle_area(20, 20);
  rectangle_area(12.6, 25);
  return 0;
}

Output

 Rectangle Size [ width : 10.000000, height : 20.000000 ]
 Rectangle Area : 200.000000

 Rectangle Size [ width : 15.500000, height : 13.400000 ]
 Rectangle Area : 207.700000

 Rectangle Size [ width : 20.000000, height : 20.000000 ]
 Rectangle Area : 400.000000

 Rectangle Size [ width : 12.600000, height : 25.000000 ]
 Rectangle Area : 315.000000
/*
  C++ program
  Calculate area of rectangle 
*/
#include<iostream>

using namespace std;
class RectangleArea
{
  public:
    //Calculate area of rectangle by given width and height
    void rectangle_area(double width, double height)
    {
      //Calculate area of rectangle
      double area = width *height;
      cout << " Rectangle Size [ width : " << width << ", height : " << height << " ] ";
      cout << "\n Rectangle Area : " << area << "\n\n";
    }
};
int main()
{
  RectangleArea obj = RectangleArea();
  //Test Cases  
  obj.rectangle_area(10, 20);
  obj.rectangle_area(15.5, 13.4);
  obj.rectangle_area(20, 20);
  obj.rectangle_area(12.6, 25);
  return 0;
}

Output

 Rectangle Size [ width : 10, height : 20 ]
 Rectangle Area : 200

 Rectangle Size [ width : 15.5, height : 13.4 ]
 Rectangle Area : 207.7

 Rectangle Size [ width : 20, height : 20 ]
 Rectangle Area : 400

 Rectangle Size [ width : 12.6, height : 25 ]
 Rectangle Area : 315
/*
  Java program
  Calculate area of rectangle 
*/
public class RectangleArea
{
  //Calculate area of rectangle by given width and height
  public void rectangle_area(double width, double height)
  {
    //Calculate area of rectangle
    double area = width * height;
    //Display the result of rectangle area
    System.out.print(" Rectangle Size [ width : " + width + ", height : " + height + " ] ");
    System.out.print("\n Rectangle Area : " + area + "\n\n");
  }
  public static void main(String[] args)
  {
    RectangleArea obj = new RectangleArea();
    //Test Cases  
    obj.rectangle_area(10, 20);
    obj.rectangle_area(15.5, 13.4);
    obj.rectangle_area(20, 20);
    obj.rectangle_area(12.6, 25);
  }
}

Output

 Rectangle Size [ width : 10.0, height : 20.0 ] 
 Rectangle Area : 200.0

 Rectangle Size [ width : 15.5, height : 13.4 ] 
 Rectangle Area : 207.70000000000002

 Rectangle Size [ width : 20.0, height : 20.0 ] 
 Rectangle Area : 400.0

 Rectangle Size [ width : 12.6, height : 25.0 ] 
 Rectangle Area : 315.0
/*
  C# program
  Calculate area of rectangle 
*/
using System;
public class RectangleArea
{
  //Calculate area of rectangle by given width and height
  public void rectangle_area(double width, double height)
  {
    //Calculate area of rectangle
    double area = width * height;
    Console.Write(" Rectangle Size [ width : " + width + ", height : " + height + " ] ");
    Console.Write("\n Rectangle Area : " + area + "\n\n");
  }
  public static void Main(String[] args)
  {
    RectangleArea obj = new RectangleArea();
    //Test Cases  
    obj.rectangle_area(10, 20);
    obj.rectangle_area(15.5, 13.4);
    obj.rectangle_area(20, 20);
    obj.rectangle_area(12.6, 25);
  }
}

Output

 Rectangle Size [ width : 10, height : 20 ]
 Rectangle Area : 200

 Rectangle Size [ width : 15.5, height : 13.4 ]
 Rectangle Area : 207.7

 Rectangle Size [ width : 20, height : 20 ]
 Rectangle Area : 400

 Rectangle Size [ width : 12.6, height : 25 ]
 Rectangle Area : 315
<?php
/*
  Php program
  Calculate area of rectangle 
*/
class RectangleArea
{
  //Calculate area of rectangle by given width and height
  public  function rectangle_area($width, $height)
  {
    //Calculate area of rectangle
    $area = $width *$height;
    //Display the result of rectangle area
    echo(" Rectangle Size [ width : ". $width .", height : ". $height ." ] ");
    echo("\n Rectangle Area : ". $area ."\n\n");
  }
}

function main()
{
  $obj = new RectangleArea();
  //Test Cases  
  $obj->rectangle_area(10, 20);
  $obj->rectangle_area(15.5, 13.4);
  $obj->rectangle_area(20, 20);
  $obj->rectangle_area(12.6, 25);
}
main();

Output

 Rectangle Size [ width : 10, height : 20 ]
 Rectangle Area : 200

 Rectangle Size [ width : 15.5, height : 13.4 ]
 Rectangle Area : 207.7

 Rectangle Size [ width : 20, height : 20 ]
 Rectangle Area : 400

 Rectangle Size [ width : 12.6, height : 25 ]
 Rectangle Area : 315
/*
  Node Js program
  Calculate area of rectangle 
*/
class RectangleArea
{
  //Calculate area of rectangle by given width and height
  rectangle_area(width, height)
  {
    //Calculate area of rectangle
    var area = width *height;
    //Display the result of rectangle area
    process.stdout.write(" Rectangle Size [ width : " + width + ", height : " + height + " ] ");
    process.stdout.write("\n Rectangle Area : " + area + "\n\n");
  }
}

function main(args)
{
  var obj = new RectangleArea();
  //Test Cases  
  obj.rectangle_area(10, 20);
  obj.rectangle_area(15.5, 13.4);
  obj.rectangle_area(20, 20);
  obj.rectangle_area(12.6, 25);
}
main();

Output

 Rectangle Size [ width : 10, height : 20 ]
 Rectangle Area : 200

 Rectangle Size [ width : 15.5, height : 13.4 ]
 Rectangle Area : 207.70000000000002

 Rectangle Size [ width : 20, height : 20 ]
 Rectangle Area : 400

 Rectangle Size [ width : 12.6, height : 25 ]
 Rectangle Area : 315
#   Python 3 program
#   Calculate area of rectangle 

class RectangleArea :
  # Calculate area of rectangle by given width and height
  def rectangle_area(self, width, height) :
    # Calculate area of rectangle
    area = width * height
    
      # Display the result of rectangle area
    print(" Rectangle Size [ width : ", width ,", height : ", height ," ] ", end = "")
    print("\n Rectangle Area : ", area ,"\n\n", end = "")
  

def main() :
  obj = RectangleArea()
  # Test Cases  
  obj.rectangle_area(10, 20)
  obj.rectangle_area(15.5, 13.4)
  obj.rectangle_area(20, 20)
  obj.rectangle_area(12.6, 25)


if __name__ == "__main__": main()

Output

 Rectangle Size [ width :  10 , height :  20  ]
 Rectangle Area :  200

 Rectangle Size [ width :  15.5 , height :  13.4  ]
 Rectangle Area :  207.70000000000002

 Rectangle Size [ width :  20 , height :  20  ]
 Rectangle Area :  400

 Rectangle Size [ width :  12.6 , height :  25  ]
 Rectangle Area :  315.0
#   Ruby program
#   Calculate area of rectangle 

class RectangleArea

  # Calculate area of rectangle by given width and height
  def rectangle_area(width, height)
  
    # Calculate area of rectangle
    area = width * height
    # Display the result of rectangle area
    print(" Rectangle Size [ width  : ", width ,", height  : ", height ," ] ")
    print("\n Rectangle Area  : ", area ,"\n\n")
  end
end
def main()

  obj = RectangleArea.new()
  # Test Cases  
  obj.rectangle_area(10, 20)
  obj.rectangle_area(15.5, 13.4)
  obj.rectangle_area(20, 20)
  obj.rectangle_area(12.6, 25)
end
main()

Output

 Rectangle Size [ width  : 10, height  : 20 ] 
 Rectangle Area  : 200

 Rectangle Size [ width  : 15.5, height  : 13.4 ] 
 Rectangle Area  : 207.70000000000002

 Rectangle Size [ width  : 20, height  : 20 ] 
 Rectangle Area  : 400

 Rectangle Size [ width  : 12.6, height  : 25 ] 
 Rectangle Area  : 315.0

/*
  Scala program
  Calculate area of rectangle 
*/
class RectangleArea
{
  //Calculate area of rectangle by given width and height
  def rectangle_area(width: Double, height: Double): Unit = {
    //Calculate area of rectangle
    var area: Double = width * height;
    //Display the result of rectangle area
    print(" Rectangle Size [ width : " + width + ", height : " + height + " ] ");
    print("\n Rectangle Area : " + area + "\n\n");
  }
}
object Main
{
  def main(args: Array[String]): Unit = {
    var obj: RectangleArea = new RectangleArea();
    //Test Cases  
    obj.rectangle_area(10, 20);
    obj.rectangle_area(15.5, 13.4);
    obj.rectangle_area(20, 20);
    obj.rectangle_area(12.6, 25);
  }
}

Output

 Rectangle Size [ width : 10.0, height : 20.0 ]
 Rectangle Area : 200.0

 Rectangle Size [ width : 15.5, height : 13.4 ]
 Rectangle Area : 207.70000000000002

 Rectangle Size [ width : 20.0, height : 20.0 ]
 Rectangle Area : 400.0

 Rectangle Size [ width : 12.6, height : 25.0 ]
 Rectangle Area : 315.0
/*
  Swift program
  Calculate area of rectangle 
*/
class RectangleArea
{
  //Calculate area of rectangle by given width and height
  func rectangle_area(_ width: Double, _ height: Double)
  {
    //Calculate area of rectangle
    let area: Double = width * height;
    
      //Display the result of rectangle area
    print(" Rectangle Size [ width : ", width ,", height : ", height ," ] ", terminator: "");
    print("\n Rectangle Area : ", area ,"\n\n", terminator: "");
  }
}
func main()
{
  let obj: RectangleArea = RectangleArea();
  //Test Cases  
  obj.rectangle_area(10, 20);
  obj.rectangle_area(15.5, 13.4);
  obj.rectangle_area(20, 20);
  obj.rectangle_area(12.6, 25);
}
main();

Output

 Rectangle Size [ width :  10.0 , height :  20.0  ]
 Rectangle Area :  200.0

 Rectangle Size [ width :  15.5 , height :  13.4  ]
 Rectangle Area :  207.7

 Rectangle Size [ width :  20.0 , height :  20.0  ]
 Rectangle Area :  400.0

 Rectangle Size [ width :  12.6 , height :  25.0  ]
 Rectangle Area :  315.0


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