多边形和矩形的面积 [英] Area of Polygon-triangle and rectangle
本文介绍了多边形和矩形的面积的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿,我有一个问题
用C#编写程序以使用多个构造函数查找多边形,三角形和矩形的面积?
这是我的答案
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
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();
}
}
但是我不知道实现多边形以及如何找到它的区域.
我从Given Link获得了解决方案,但无法理解第一个构造方法
答案 [
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.
推荐答案
稍作谷歌搜索就能回答您的问题:
A little googling would have answered your question:
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);
}
}
这篇关于多边形和矩形的面积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文