Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp38
- {
- struct Point
- {
- int x;
- int y;
- public Point(int x, int y)
- {
- this.x = x;
- this.y = y;
- }
- public override string ToString()
- {
- return $" X: {x} Y: {y}";
- }
- public int X
- {
- get { return x; }
- set { x = value; }
- }
- public int Y
- {
- get { return y; }
- set { y = value; }
- }
- public static Point operator -(Point p1, Point p2)
- {
- return new Point { x = p1.x - p2.x, y = p1.y - p2.y };
- }
- }
- class PointList : IEnumerable
- {
- private Point[] P;
- public PointList(Point[] List)
- {
- P = List;
- Count = P.Length;
- }
- public int Count { get; set; }
- public void Add(Point item)
- {
- Point[] temp = new Point[P.Length + 1];
- for (int i=0; i < P.Length; i++)
- {
- temp[i] = P[i];
- }
- P = temp;
- P[Count] = item;
- Count++;
- }
- public void Del()
- {
- Point[] temp = new Point[P.Length - 1];
- for (int i = 0; i < P.Length - 1; i++)
- {
- temp[i] = P[i];
- }
- P = temp;
- Count--;
- }
- public void DelAt(int index)
- {
- Point[] temp = new Point[P.Length - 1];
- int Counter = 0;
- for (int i = 0; i < P.Length - 1; i++)
- {
- if (i != index) { temp[Counter] = P[i]; Counter++; }
- }
- P = temp;
- Count--;
- }
- public void Array()
- {
- Console.WriteLine("-----------");
- for (int i=0; i < P.Length; i++)
- {
- Console.WriteLine(P[i]);
- }
- Console.WriteLine("-----------");
- }
- public Point this[int index]
- {
- get {return P[index];}
- }
- public IEnumerator GetEnumerator()
- {
- return P.GetEnumerator();
- }
- }
- class Points
- {
- private Point[] P;
- public Points(int capacity)
- {
- P = new Point[capacity];
- Count = 0;
- Capacity = capacity;
- }
- public int Count { get; set; }
- public int Capacity { get; set; }
- public void Add(Point item)
- {
- if (Count+1 > Capacity)
- {
- Point[] temp = new Point[Capacity + 5];
- for (int i=0; i < Capacity; i++)
- {
- temp[i] = P[i];
- }
- Capacity += 5;
- temp[Count] = item;
- Count++;
- }
- else
- {
- P[Count] = item;
- Count++;
- }
- }
- public void Del()
- {
- Point[] temp = new Point[Count - 1];
- for(int i = 0; i < Count - 1; i++)
- {
- temp[i] = P[i];
- }
- P = temp;
- Capacity = Count - 1;
- Count--;
- }
- public void DelAt(int index)
- {
- Point[] temp = new Point[P.Length - 1];
- int Counter = 0;
- for (int i = 0; i < P.Length - 1; i++)
- {
- if (i != index) { temp[Counter] = P[i]; Counter++; }
- }
- P = temp;
- Count--;
- Capacity--;
- }
- public void Array()
- {
- Console.WriteLine("***********");
- for (int i = 0; i < P.Length; i++)
- {
- Console.WriteLine(P[i]);
- }
- Console.WriteLine("***********");
- }
- public Point this[int index]
- {
- get {return P[index];}
- }
- public IEnumerator GetEnumerator()
- {
- return P.GetEnumerator();
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Point point1 = new Point(10, 5);
- Point point2 = new Point(9, 4);
- Point point3 = point1 - point2;
- Console.WriteLine("Point 1 " + point1);
- Console.WriteLine("Point 2 " + point2);
- Console.WriteLine("Point 1 - Point 2 " + point3);
- Console.WriteLine();
- Point[] list = new Point[2] { point1, point2 };
- PointList ptList = new PointList(list);
- ptList.Add(point3);
- ptList.Array();
- Point point4 = new Point(20, 15);
- Point point5 = new Point(10, 5);
- Point point6 = point4 - point5;
- Console.WriteLine("Point 4 " + point4);
- Console.WriteLine("Point 5 " + point5);
- Console.WriteLine("Point 4 - Point 5 " + point6);
- Console.WriteLine();
- Points L = new Points(5);
- L.Add(point4);
- L.Add(point5);
- L.Add(point6);
- L.Array();
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement