Advertisement
RMarK0

Untitled

Apr 24th, 2021
848
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.46 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 ConsoleApp38
  8. {
  9.    struct Point
  10.     {
  11.         int x;
  12.         int y;
  13.  
  14.         public Point(int x, int y)
  15.         {
  16.             this.x = x;
  17.             this.y = y;
  18.         }
  19.  
  20.         public override string ToString()
  21.         {
  22.             return $" X: {x}  Y: {y}";
  23.         }
  24.  
  25.         public int X
  26.         {
  27.             get { return x;  }
  28.             set { x = value; }
  29.         }
  30.  
  31.         public int Y
  32.         {
  33.             get { return y;  }
  34.             set { y = value; }
  35.         }
  36.  
  37.         public static Point operator -(Point p1, Point p2)
  38.         {
  39.             return new Point { x = p1.x - p2.x, y = p1.y - p2.y };
  40.         }
  41.  
  42.     }
  43.  
  44.     class PointList : IEnumerable
  45.     {
  46.         private Point[] P;
  47.  
  48.         public PointList(Point[] List)
  49.         {
  50.             P = List;
  51.             Count = P.Length;
  52.         }
  53.  
  54.         public int Count { get; set; }
  55.  
  56.         public void Add(Point item)
  57.         {
  58.             Point[] temp = new Point[P.Length + 1];
  59.             for (int i=0; i < P.Length; i++)
  60.             {
  61.                 temp[i] = P[i];
  62.             }
  63.             P = temp;
  64.             P[Count] = item;
  65.             Count++;
  66.         }
  67.  
  68.         public void Del()
  69.         {
  70.             Point[] temp = new Point[P.Length - 1];
  71.             for (int i = 0; i < P.Length - 1; i++)
  72.             {
  73.                 temp[i] = P[i];
  74.             }
  75.             P = temp;
  76.             Count--;
  77.         }
  78.  
  79.         public void DelAt(int index)
  80.         {
  81.             Point[] temp = new Point[P.Length - 1];
  82.             int Counter = 0;
  83.             for (int i = 0; i < P.Length - 1; i++)
  84.             {
  85.                 if (i != index) { temp[Counter] = P[i]; Counter++; }
  86.             }
  87.             P = temp;
  88.             Count--;
  89.         }
  90.  
  91.         public void Array()
  92.         {
  93.             Console.WriteLine("-----------");
  94.  
  95.             for (int i=0; i < P.Length; i++)
  96.             {
  97.                 Console.WriteLine(P[i]);
  98.             }
  99.  
  100.             Console.WriteLine("-----------");
  101.         }
  102.        
  103.         public Point this[int index]
  104.         {
  105.             get {return P[index];}
  106.         }
  107.        
  108.         public IEnumerator GetEnumerator()
  109.         {
  110.             return P.GetEnumerator();
  111.         }
  112.     }
  113.  
  114.     class Points
  115.     {
  116.         private Point[] P;
  117.         public Points(int capacity)
  118.         {
  119.             P = new Point[capacity];
  120.             Count = 0;
  121.             Capacity = capacity;
  122.         }
  123.  
  124.         public int Count { get; set; }
  125.         public int Capacity { get; set; }
  126.  
  127.         public void Add(Point item)
  128.         {
  129.             if (Count+1 > Capacity)
  130.             {
  131.                 Point[] temp = new Point[Capacity + 5];
  132.                 for (int i=0; i < Capacity; i++)
  133.                 {
  134.                     temp[i] = P[i];
  135.                 }
  136.                 Capacity += 5;
  137.                 temp[Count] = item;
  138.                 Count++;
  139.             }
  140.             else
  141.             {
  142.                 P[Count] = item;
  143.                 Count++;
  144.             }
  145.         }
  146.  
  147.         public void Del()
  148.         {
  149.             Point[] temp = new Point[Count - 1];
  150.             for(int i = 0; i < Count - 1; i++)
  151.             {
  152.                 temp[i] = P[i];
  153.             }
  154.             P = temp;
  155.             Capacity = Count - 1;
  156.             Count--;
  157.         }
  158.  
  159.         public void DelAt(int index)
  160.         {
  161.             Point[] temp = new Point[P.Length - 1];
  162.             int Counter = 0;
  163.             for (int i = 0; i < P.Length - 1; i++)
  164.             {
  165.                 if (i != index) { temp[Counter] = P[i]; Counter++; }
  166.             }
  167.             P = temp;
  168.             Count--;
  169.             Capacity--;
  170.         }
  171.  
  172.         public void Array()
  173.         {
  174.             Console.WriteLine("***********");
  175.  
  176.             for (int i = 0; i < P.Length; i++)
  177.             {
  178.                 Console.WriteLine(P[i]);
  179.             }
  180.  
  181.             Console.WriteLine("***********");
  182.         }
  183.        
  184.         public Point this[int index]
  185.         {
  186.             get {return P[index];}
  187.         }
  188.        
  189.         public IEnumerator GetEnumerator()
  190.         {
  191.             return P.GetEnumerator();
  192.         }
  193.     }
  194.  
  195.     class Program
  196.     {
  197.         static void Main(string[] args)
  198.         {
  199.             Point point1 = new Point(10, 5);
  200.             Point point2 = new Point(9, 4);
  201.             Point point3 = point1 - point2;
  202.  
  203.             Console.WriteLine("Point 1   " + point1);
  204.             Console.WriteLine("Point 2   " + point2);
  205.             Console.WriteLine("Point 1 - Point 2    " + point3);
  206.             Console.WriteLine();
  207.  
  208.             Point[] list = new Point[2] { point1, point2 };
  209.             PointList ptList = new PointList(list);
  210.  
  211.             ptList.Add(point3);
  212.             ptList.Array();
  213.  
  214.             Point point4 = new Point(20, 15);
  215.             Point point5 = new Point(10, 5);
  216.             Point point6 = point4 - point5;
  217.             Console.WriteLine("Point 4   " + point4);
  218.             Console.WriteLine("Point 5   " + point5);
  219.             Console.WriteLine("Point 4 - Point 5    " + point6);
  220.             Console.WriteLine();
  221.  
  222.             Points L = new Points(5);
  223.             L.Add(point4);
  224.             L.Add(point5);
  225.             L.Add(point6);
  226.             L.Array();
  227.  
  228.             Console.ReadKey();
  229.         }
  230.     }
  231. }
  232.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement