Advertisement
sokolova4

Задача 3

Nov 5th, 2020
1,762
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. public class Polygon
  5. { // Класс многоугольников
  6.     int numb;       // Число сторон
  7.     double radius;  // Радиус вписанной окружности
  8.     public Polygon(int n = 3, double r = 1)
  9.     { // конструктор      
  10.         numb = n;
  11.         radius = r;
  12.     }
  13.     public double Perimeter
  14.     { // Периметр многоугольника - свойство
  15.         get
  16.         {   // аксессор свойства
  17.             double term = Math.Tan(Math.PI / numb);
  18.             return 2 * numb * radius * term;
  19.         }
  20.     }
  21.  
  22.     public double Area
  23.     { // Площадь многоугольника - свойство
  24.         get
  25.         {   // аксессор свойства
  26.             return Perimeter * radius / 2;
  27.         }
  28.     }
  29.     public string PolygonData()
  30.     {
  31.         string res =
  32.         string.Format("N={0}; R={1}; P={2,2:F3}; S={3,4:F3}",
  33.         numb, radius, Perimeter, Area);
  34.         return res;
  35.     }
  36. }   // Polygon
  37. public class Program
  38. {
  39.     public static void Main()
  40.     {
  41.  
  42.         List<Polygon> array = new List<Polygon>();
  43.         Polygon polygon = new Polygon();
  44.         double r = 1;
  45.         int numb = 1;
  46.         double MinArea = double.MaxValue;
  47.         double MaxArea = double.MinValue;
  48.         while (true)
  49.         {
  50.             do Console.Write("Введите число сторон: ");
  51.             while (!int.TryParse(Console.ReadLine(), out numb) | numb < 0);
  52.             do Console.Write("Введите радиус: ");
  53.             while (!double.TryParse(Console.ReadLine(), out r) | r < 0);
  54.             if (r == 0 && numb == 0) break;
  55.             array.Add(new Polygon(numb, r));
  56.             Console.WriteLine("Введен многоугольник:");
  57.             Console.WriteLine(array[array.Count - 1].PolygonData());
  58.             MinArea = Math.Min(MinArea, array[array.Count - 1].Area);
  59.             MaxArea = Math.Max(MaxArea, array[array.Count - 1].Area);
  60.  
  61.         }
  62.         /*double MinArea = array.Min(it => it.Area);
  63.         double MaxArea = array.Max(it => it.Area);*/
  64.         foreach (var item in array)
  65.         {
  66.             if (item.Area == MinArea)
  67.             {
  68.                 Console.ForegroundColor = ConsoleColor.Green;
  69.             }
  70.             else if(item.Area == MaxArea)
  71.             {
  72.                 Console.ForegroundColor = ConsoleColor.Red;
  73.             }
  74.             Console.WriteLine(item.PolygonData());
  75.             Console.ForegroundColor = ConsoleColor.White;
  76.         }
  77.  
  78.  
  79.         Console.WriteLine("По умолчанию создан многоугольник: ");
  80.         Console.WriteLine(polygon.PolygonData());
  81.         double rad;
  82.         int number;
  83.         do
  84.         {
  85.             do Console.Write("Введите число сторон: ");
  86.             while (!int.TryParse(Console.ReadLine(), out number) | number < 3);
  87.             do Console.Write("Введите радиус: ");
  88.             while (!double.TryParse(Console.ReadLine(), out rad) | rad < 0);
  89.             polygon = new Polygon(number, rad);
  90.             Console.WriteLine("Сведения о многоугольнике:");
  91.             Console.WriteLine(polygon.PolygonData());
  92.             Console.WriteLine("Для выхода нажмите клавишу ESC");
  93.         } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
  94.  
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement