Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class Polygon
- { // Класс многоугольников
- int numb; // Число сторон
- double radius; // Радиус вписанной окружности
- public Polygon(int n = 3, double r = 1)
- { // конструктор
- numb = n;
- radius = r;
- }
- public double Perimeter
- { // Периметр многоугольника - свойство
- get
- { // аксессор свойства
- double term = Math.Tan(Math.PI / numb);
- return 2 * numb * radius * term;
- }
- }
- public double Area
- { // Площадь многоугольника - свойство
- get
- { // аксессор свойства
- return Perimeter * radius / 2;
- }
- }
- public string PolygonData()
- {
- string res =
- string.Format("N={0}; R={1}; P={2,2:F3}; S={3,4:F3}",
- numb, radius, Perimeter, Area);
- return res;
- }
- } // Polygon
- public class Program
- {
- public static void Main()
- {
- List<Polygon> array = new List<Polygon>();
- Polygon polygon = new Polygon();
- double r = 1;
- int numb = 1;
- double MinArea = double.MaxValue;
- double MaxArea = double.MinValue;
- while (true)
- {
- do Console.Write("Введите число сторон: ");
- while (!int.TryParse(Console.ReadLine(), out numb) | numb < 0);
- do Console.Write("Введите радиус: ");
- while (!double.TryParse(Console.ReadLine(), out r) | r < 0);
- if (r == 0 && numb == 0) break;
- array.Add(new Polygon(numb, r));
- Console.WriteLine("Введен многоугольник:");
- Console.WriteLine(array[array.Count - 1].PolygonData());
- MinArea = Math.Min(MinArea, array[array.Count - 1].Area);
- MaxArea = Math.Max(MaxArea, array[array.Count - 1].Area);
- }
- /*double MinArea = array.Min(it => it.Area);
- double MaxArea = array.Max(it => it.Area);*/
- foreach (var item in array)
- {
- if (item.Area == MinArea)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- }
- else if(item.Area == MaxArea)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- }
- Console.WriteLine(item.PolygonData());
- Console.ForegroundColor = ConsoleColor.White;
- }
- Console.WriteLine("По умолчанию создан многоугольник: ");
- Console.WriteLine(polygon.PolygonData());
- double rad;
- int number;
- do
- {
- do Console.Write("Введите число сторон: ");
- while (!int.TryParse(Console.ReadLine(), out number) | number < 3);
- do Console.Write("Введите радиус: ");
- while (!double.TryParse(Console.ReadLine(), out rad) | rad < 0);
- polygon = new Polygon(number, rad);
- Console.WriteLine("Сведения о многоугольнике:");
- Console.WriteLine(polygon.PolygonData());
- Console.WriteLine("Для выхода нажмите клавишу ESC");
- } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement