Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. using System;
  2.  
  3. public class Polygon
  4. { // Класс многоугольников
  5. int numb; // Число сторон
  6. double radius; // Радиус вписанной окружности
  7. public Polygon(int n = 3, double r = 1)
  8. { // конструктор
  9. numb = n;
  10. radius = r;
  11. }
  12. // СВОЙСТВО PERIMETR
  13. // СВОЙСТВО AREA
  14. public double Perimeter
  15. { // Периметр многоугольника - свойство
  16. get
  17. { // аксессор свойства
  18. double term = Math.Tan(Math.PI / numb);
  19. return 2 * numb * radius * term;
  20. }
  21. }
  22.  
  23. public double Area
  24. { // Площадь многоугольника - свойство
  25. get
  26. { // аксессор свойства
  27. return Perimeter * radius / 2;
  28. }
  29. }
  30.  
  31. public string PolygonData()
  32. {
  33. string res =
  34. string.Format("N={0}; R={1}; P={2,2:F3}; S={3,4:F3}",
  35. numb, radius, Perimeter, Area);
  36. return res;
  37. }
  38. } // Polygon
  39. public class Program
  40. {
  41. static void Main()
  42. {
  43. Polygon polygon = new Polygon();
  44. Console.WriteLine("По умолчанию создан многоугольник: ");
  45. Console.WriteLine(polygon.PolygonData());
  46. double rad;
  47. int number;
  48. do
  49. {
  50. do Console.Write("Введите число сторон: ");
  51. while (!int.TryParse(Console.ReadLine(), out number) | number < 3);
  52. do Console.Write("Введите радиус: ");
  53. while (!double.TryParse(Console.ReadLine(), out rad) | rad < 0);
  54. polygon = new Polygon(number, rad);
  55. Console.WriteLine("Сведения о многоугольнике:");
  56. Console.WriteLine(polygon.PolygonData());
  57. Console.WriteLine("Для выхода нажмите клавишу ESC");
  58. } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
  59.  
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement