Advertisement
Danvil

[C#] Структура.Многоугольники

Mar 19th, 2017
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Структура.Многоугольники
  8. {
  9.     struct Polygon
  10.     {
  11.         double[] intCoordX;
  12.         double[] intCoordY;
  13.         double dblLineThickness;
  14.         uint intLineColor;
  15.         bool blnIsFilled;
  16.  
  17.         public Polygon(double[] x, double[] y, double Thick, uint Color, bool Fill)
  18.         {
  19.             intCoordX = x;
  20.             intCoordY = y;
  21.             dblLineThickness = Thick;
  22.             intLineColor = Color;
  23.             blnIsFilled = Fill;
  24.         }
  25.         public bool Check()
  26.         {
  27.             if (ifEqualSides() && ifFilled() && ifHaveFourSides())
  28.                 return true;
  29.             else
  30.                 return false;
  31.         }
  32.         bool ifEqualSides()
  33.         {
  34.             if (((Math.Sqrt(Math.Pow(intCoordY[1] - intCoordY[0], 2) + Math.Pow(intCoordX[1] - intCoordX[0], 2)) == Math.Sqrt(Math.Pow(intCoordY[2] - intCoordY[1], 2) + Math.Pow(intCoordX[2] - intCoordX[1], 2))) && (Math.Sqrt(Math.Pow(intCoordY[2] - intCoordY[1], 2) + Math.Pow(intCoordX[2] - intCoordX[1], 2)) == Math.Sqrt(Math.Pow(intCoordY[3] - intCoordY[2], 2) + Math.Pow(intCoordX[3] - intCoordX[2], 2))) && (Math.Sqrt(Math.Pow(intCoordY[3] - intCoordY[2], 2) + Math.Pow(intCoordX[3] - intCoordX[2], 2)) == Math.Sqrt(Math.Pow(intCoordY[0] - intCoordY[3], 2) + Math.Pow(intCoordX[0] - intCoordX[3], 2)))))
  35.                 return true;
  36.             else
  37.                 return false;
  38.            
  39.         }
  40.         bool ifFilled()
  41.         {
  42.             return blnIsFilled;
  43.         }
  44.         int SideCount()
  45.         {
  46.             return intCoordX.Length;
  47.         }
  48.         bool ifHaveFourSides()
  49.         {
  50.             if (SideCount() == 4)
  51.                 return true;
  52.             else
  53.                 return false;
  54.         }
  55.     }
  56.     class Program
  57.     {
  58.         static void Main(string[] args)
  59.         {
  60.             Console.WriteLine("Введите количество многоугольников");
  61.             int intPolyCount = int.Parse(Console.ReadLine());
  62.             Polygon[] arrPolygon = new Polygon[intPolyCount];
  63.             for (int intCurPoly = 0; intCurPoly < arrPolygon.Length; intCurPoly++)
  64.             {
  65.                 Console.WriteLine("=== Многоугольник {0} ===", intCurPoly + 1);
  66.                 Console.WriteLine("Введите количество вершин");
  67.                 int intCount = int.Parse(Console.ReadLine());
  68.                 double[] arrX = new double[intCount];
  69.                 double[] arrY = new double[intCount];
  70.                 Console.WriteLine("Введите координаты вершин многоугольника (по часовой стрелке):");
  71.                 for (int intC = 0; intC < intCount; intC++)
  72.                 {
  73.                     Console.Write("X: ");
  74.                     arrX[intC] = int.Parse(Console.ReadLine());
  75.                     Console.Write("Y: ");
  76.                     arrY[intC] = int.Parse(Console.ReadLine());
  77.                 }
  78.                 Console.WriteLine("Введите толщину линий");
  79.                 double intLineThickness = double.Parse(Console.ReadLine());
  80.                 Console.WriteLine("Введите цвет линий");
  81.                 uint intLineColor = uint.Parse(Console.ReadLine());
  82.                 Console.WriteLine("Введите наличие заливки (true/false)");
  83.                 bool ifFilled = bool.Parse(Console.ReadLine());
  84.                 arrPolygon[intCurPoly] = new Polygon(arrX, arrY, intLineThickness, intLineColor, ifFilled);
  85.             }
  86.             int intCur = 0;
  87.             foreach (Polygon objPoly in arrPolygon)
  88.             {
  89.                 if (objPoly.Check())
  90.                     Console.WriteLine("{0}) Многоугольник прошел проверку!", intCur+1);
  91.                 else
  92.                     Console.WriteLine("{0}) Многоугольник не прошел проверку!", intCur+1);
  93.                 intCur++;
  94.             }
  95.         }
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement