Guest User

Untitled

a guest
Dec 9th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6.  
  7. namespace ConsoleApplication1
  8. {
  9.  
  10. class Point
  11. {
  12. private int x;
  13. private int y;
  14.  
  15. public Point()
  16. {
  17. x = 0;
  18. y = 0;
  19. }
  20.  
  21. public Point(int x, int y)
  22. {
  23. this.x = x;
  24. this.y = y;
  25. }
  26.  
  27. public void Show()
  28. {
  29. Console.WriteLine("Point: ({0}, {1})", x, y);
  30. }
  31.  
  32. public double Distance()
  33. {
  34. return Math.Sqrt(x * x + y * y);
  35. }
  36.  
  37. public void Move(int a, int b)
  38. {
  39. x += a;
  40. y += b;
  41. }
  42.  
  43. public int X
  44. {
  45. get {
  46. return x;
  47. }
  48.  
  49. set {
  50. x = value;
  51. }
  52. }
  53.  
  54. public int Y
  55. {
  56. get
  57. {
  58. return y;
  59. }
  60.  
  61. set
  62. {
  63. y = value;
  64. }
  65. }
  66.  
  67. public int ScalarMult
  68. {
  69. set
  70. {
  71. x *= value;
  72. y *= value;
  73. }
  74. }
  75.  
  76. public int this[int i] {
  77. get
  78. {
  79. if (i == 0)
  80. return x;
  81. else
  82. {
  83. if (i == 1)
  84. return y;
  85. else
  86. {
  87. Console.WriteLine("Недопустимый индекс");
  88. return 0;
  89. }
  90. }
  91. }
  92.  
  93. set
  94. {
  95. if (i == 0)
  96. x = value;
  97. else
  98. {
  99. if (i == 1)
  100. y = value;
  101. else
  102. {
  103. Console.WriteLine("Недопустимый индекс");
  104. }
  105. }
  106. }
  107. }
  108.  
  109.  
  110. public static Point operator++(Point a) {
  111. Point temp = new Point();
  112. temp[0] = a[0] + 1;
  113. temp[1] = a[1] + 1;
  114. return temp;
  115. }
  116.  
  117. public static Point operator --(Point a)
  118. {
  119. Point temp = new Point();
  120. temp[0] = a[0] - 1;
  121. temp[1] = a[1] - 1;
  122. return temp;
  123. }
  124.  
  125. public static bool operator true(Point a)
  126. {
  127. if (a[0] == a[1])
  128. return true;
  129. else
  130. return false;
  131. }
  132.  
  133. public static bool operator false(Point a)
  134. {
  135. if (a[0] != a[1])
  136. return true;
  137. else
  138. return false;
  139. }
  140.  
  141. public static Point operator+(Point a, int b)
  142. {
  143. a[0] += b;
  144. a[1] += b;
  145. return a;
  146. }
  147. }
  148.  
  149. class Program
  150. {
  151. static void Main(string[] args)
  152. {
  153. Point point1 = new Point();
  154. Point point2 = new Point(3, 2);
  155.  
  156. point1.Show();
  157. Console.WriteLine("Point 2 distance: {0}", point2.Distance());
  158.  
  159. point1.Move(5, 5);
  160. point1.Show();
  161.  
  162. point2.X = 10;
  163. point2.Y = 4;
  164.  
  165. point1.ScalarMult = 3;
  166. point1.Show();
  167. point2.Show();
  168.  
  169. Console.WriteLine("Point 1 first coordinate: {0}", point1[0]);
  170. Console.WriteLine("Point 2 second coordinate: {0}", point2[1]);
  171.  
  172. point1++;
  173. point1.Show();
  174.  
  175. point2--;
  176. point2.Show();
  177.  
  178. if (point1)
  179. {
  180. Console.WriteLine("First and second coordinate are equals");
  181. }
  182.  
  183. point2 = point2 + 5;
  184. point2.Show();
  185. }
  186. }
  187. }
Add Comment
Please, Sign In to add comment