Advertisement
Margoshinka

LineSegment

Sep 18th, 2021
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace lab2
  6. {
  7. class LineSegment
  8. {
  9. double x;
  10. double y;
  11. public double X
  12. {
  13. get { return x; }
  14. set
  15. {
  16.  
  17. x = value;
  18. }
  19.  
  20. }
  21. public double Y
  22. {
  23. get { return y; }
  24. set
  25. {
  26. y = value;
  27. }
  28.  
  29. }
  30. public LineSegment(double x, double y)
  31. {
  32. X = x;
  33. Y = y;
  34.  
  35.  
  36. }
  37. public LineSegment()
  38. {
  39. x= 0;
  40. y = 0;
  41. }
  42. public override string ToString()
  43. {
  44. return "Отрезок с координатами " + x.ToString() + " и " + y.ToString();
  45.  
  46. }
  47. public bool Entrance(double cor)
  48. {
  49. bool l = cor <= y && cor >= x;
  50.  
  51.  
  52.  
  53. return l;
  54. }
  55. public static double operator !(LineSegment l) //длина отрезка
  56. {
  57. double rs = l.y - l.x;
  58. return rs;
  59. }
  60. public static LineSegment operator ++(LineSegment l) // увеличить координаты границ на 1
  61. {
  62. l.Y++;
  63. l.X++;
  64. return l;
  65. }
  66. /*public static implicit operator double (LineSegment l) // неявное преобразование, закомментила потому что не выведет примеры на конструкторы
  67. {
  68. return l.y;
  69. }*/
  70. public static explicit operator int(LineSegment l) // явное преобразование
  71. {
  72. return (int)l.x;
  73. }
  74. public static LineSegment operator +(LineSegment l, int d) //координаты увеличиваются на d
  75. {
  76. LineSegment temp = new LineSegment();
  77. temp.x=l.x + d;
  78. temp.y=l.y + d;
  79. return temp;
  80. }
  81. public static LineSegment operator +(int d, LineSegment l)
  82. {
  83. LineSegment temp = new LineSegment();
  84. temp.x = l.x + d;
  85. temp.y = l.y + d;
  86. return temp;
  87. }
  88. public static bool operator <(LineSegment l, int d) //попадает ли число в заданный отрезок
  89. {
  90. bool res;
  91. if (d >= l.x && d <= l.y) res = true;
  92. else res = false;
  93. return res;
  94. }
  95. public static bool operator >(LineSegment l, int d)
  96. {
  97. bool res;
  98. /*if (d >= l.x && d <= l.y) res = true;
  99. else res = false;
  100. return res;*/
  101. return false;
  102. }
  103. }
  104. }
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement