Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hey I have a question

Write a program in C# to find the area of polygon, triangle and rectangle by using multiple constructors?

and here is my answer
C#
class Area
{
    public Area(double x, double y)
    {
        double res = .5 * x * y;
        Console.WriteLine("Area of triangle "+res);
    }

    public Area(int x, int y)
    {
        int res = x * y;
        Console.WriteLine("Area of Rectangle "+res);
    }

    static void Main(string[] args)
    {
        Area obj = new Area(20.50, 50.10);
        obj = new Area(10,10);
        Console.ReadLine();
    }
}


but I have no idea about implementing polygon and how to find it area.


I got Solution from Given Link but I unable to understand first Constructor Method
Answer[^]

please Help me.
Posted
Updated 24-Nov-10 4:13am
v4

1 solution

A little googling would have answered your question:

C#
public class Area
{
    public static double AreaPolygon(int[] x, int[] y, int noOfPoints)
    {
        double area = 0;
        for (int i = 0; i < noOfPoints; i++)
        {
            area = area + ((x[i] * y[i+1]) - (x[i + 1] * y[i]))
        }
        area = area * 0.5;
        return area;
    }

    public static double AreaTriangle(int b, int h)
    {
        return (b * h) * 0.5;
    }

    public static double AreaRectangle(int l, int h)
    {
        return (l * h);
    }
}
 
Share this answer
 
v3
Comments
ShilpaKumari 24-Nov-10 9:33am    
I also found this program from this http://www.dotnetspider.com/forum/110446-write-program-c-find-e-area-polygon.aspx Link but I Unable to find out which formula is working. will you elaborate please..
#realJSOP 24-Nov-10 9:43am    
Did you run it and see what happens? Are you a programmer, or did you somehow gain access to a programmer's computer, and you're just messing around?
ShilpaKumari 24-Nov-10 9:51am    
Ya I Run it and also use break point to take snaps of every steps but I want to know Which polygon works here. I am not able to find it.
I also move for Google but it shows a lots of formula for polygon
#realJSOP 24-Nov-10 9:55am    
I'm sorry. If you can't determine what's happening, then no amount of "clarification" from me can help you.
CPallini 24-Nov-10 13:47pm    
I works for many different polygons. You may find the formula derivation, with its limitations, here: http://local.wasp.uwa.edu.au/~pbourke/geometry/polyarea/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900