Land Area Calculation with Heron's Formula in C#

Introduction

In the vast domain of land assessment and surveying, accurately measuring land area is paramount. Whether you're a real estate developer, a farmer planning crop distribution, or a homeowner looking to understand property dimensions, having a reliable method for land area calculation is essential. In this article, we'll explore how to utilize Heron's formula, a geometric approach, to calculate land area using a straightforward C# program. This program empowers users to input side lengths of adjoining triangles and effortlessly determine the total land area. Let's delve into the implementation.

Understanding Heron's Formula

Heron's formula provides an elegant solution for calculating the area of a triangle given the lengths of its three sides. For a triangle with side lengths ( a ), ( b ), and ( c ), the formula is as follows:

Heron's Formula

where ( s ) represents the semi-perimeter of the triangle.

semi-perimeter of the triangle

Heron's formula is particularly useful for calculating the area of irregularly shaped triangles without relying on angles or heights.

Implementing the C# Program

Below is the C# program that implements Heron's formula for land area calculation. The program guides users through entering side lengths of adjoining triangles and provides the total land area in square feet, along with an option to convert it to Biswa.

using System;

class Program
{
    static void Main(string[] args)
    {
        bool restart = true;
        while (restart)
        {
            // User input for side lengths of triangles
            Console.WriteLine("Enter the length of side AB:");
            double AB = double.Parse(Console.ReadLine());

            Console.WriteLine("Enter the length of side BC:");
            double BC = double.Parse(Console.ReadLine());

            Console.WriteLine("Enter the length of side CD:");
            double CD = double.Parse(Console.ReadLine());

            Console.WriteLine("Enter the length of side DA:");
            double DA = double.Parse(Console.ReadLine());

            // Calculate areas of triangles using Heron's formula
            double areaABD = CalculateTriangleArea(AB, CalculateDiagonalLength(AB, DA), DA);
            double areaBCD = CalculateTriangleArea(BC, CalculateDiagonalLength(BC, CD), CD);

            // Total land area calculation
            double totalAreaInSquareFeet = areaABD + areaBCD;

            // Display total land area in square feet
            Console.WriteLine("Total area in Square Feet: " + totalAreaInSquareFeet + " Feet");

            // Convert total area to Biswa
            double totalAreaInBiswa = ConvertToBiswa(totalAreaInSquareFeet);
            Console.WriteLine("Total area in Biswa: " + totalAreaInBiswa + " Biswa");

            // Prompt user to restart or exit
            Console.WriteLine("Do you want to restart? (Y/N)");
            string input = Console.ReadLine();
            restart = (input.Trim().ToUpper() == "Y");
        }
    }

    // Function to calculate diagonal length using Pythagoras' theorem
    static double CalculateDiagonalLength(double side1, double side2)
    {
        return Math.Sqrt(Math.Pow(side1, 2) + Math.Pow(side2, 2));
    }

    // Function to calculate triangle area using Heron's formula
    static double CalculateTriangleArea(double side1, double diagonal, double side2)
    {
        double s = (side1 + diagonal + side2) / 2;
        return Math.Sqrt(s * (s - side1) * (s - diagonal) * (s - side2));
    }

    // Function to convert square feet to Biswa
    static double ConvertToBiswa(double squareFeet)
    {
        // 1 Biswa = 1350 square feet
        return squareFeet / 1350.0;
    }
}

Example Usage

Let's consider an example where we have a plot of land with the following side lengths.

  • ( AB = 30 ) feet
  • ( BC = 20 ) feet
  • ( CD = 24 ) feet
  • ( DA = 30 ) feet

Upon running the program with these inputs, it will prompt you for each side length, calculate the total land area, and display the result.

Result

The program provides the total land area in both square feet and Biswa, offering flexibility and convenience for users from various backgrounds.

Conclusion

By combining the simplicity of C# programming with the mathematical elegance of Heron's formula, this program offers a user-friendly solution for land area calculation. Whether you're a land surveyor, a homeowner, or a student learning about geometry, this program serves as a practical tool for understanding and estimating land area in real-world scenarios.

😊Please consider liking and following me for more articles and if you find this content helpful.👍


Citiustech Healthcare Technology Pvt Ltd
CitiusTech plays a deep and meaningful role in powering the future of healthcare.