コード例 #1
0
 public static void Main()
 {
     Console.WriteLine("Program that calculates the perimeter and the area of given polygon consisting of n floating-point coordinates in the 2D plane.");
     Console.Write("Write n = ");
     int n = int.Parse(Console.ReadLine());
     List<Point> listOfPoints = new List<Point>
     {
     };
     for (int i = 0; i < n; i++)
     {
         Console.Write("Write coordinates of point {0}: ", i + 1);
         string line = Console.ReadLine();
         string[] list = line.Split(' ');
         double x = double.Parse(list[0]);
         double y = double.Parse(list[1]);
         Point p = new Point(x, y);
         listOfPoints.Add(p);
     }
     Polygon polygon = new Polygon(listOfPoints);
     double perimeter = polygon.Perimeter();
     double area = polygon.Area();
     Console.WriteLine("perimeter = {0:0.00}", perimeter);
     Console.WriteLine("area = {0:0.00}", area);
 }