Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace lab2
- {
- class LineSegment
- {
- double x;
- double y;
- public double X
- {
- get { return x; }
- set
- {
- x = value;
- }
- }
- public double Y
- {
- get { return y; }
- set
- {
- y = value;
- }
- }
- public LineSegment(double x, double y)
- {
- X = x;
- Y = y;
- }
- public LineSegment()
- {
- x= 0;
- y = 0;
- }
- public override string ToString()
- {
- return "Отрезок с координатами " + x.ToString() + " и " + y.ToString();
- }
- public bool Entrance(double cor)
- {
- bool l = cor <= y && cor >= x;
- return l;
- }
- public static double operator !(LineSegment l) //длина отрезка
- {
- double rs = l.y - l.x;
- return rs;
- }
- public static LineSegment operator ++(LineSegment l) // увеличить координаты границ на 1
- {
- l.Y++;
- l.X++;
- return l;
- }
- /*public static implicit operator double (LineSegment l) // неявное преобразование, закомментила потому что не выведет примеры на конструкторы
- {
- return l.y;
- }*/
- public static explicit operator int(LineSegment l) // явное преобразование
- {
- return (int)l.x;
- }
- public static LineSegment operator +(LineSegment l, int d) //координаты увеличиваются на d
- {
- LineSegment temp = new LineSegment();
- temp.x=l.x + d;
- temp.y=l.y + d;
- return temp;
- }
- public static LineSegment operator +(int d, LineSegment l)
- {
- LineSegment temp = new LineSegment();
- temp.x = l.x + d;
- temp.y = l.y + d;
- return temp;
- }
- public static bool operator <(LineSegment l, int d) //попадает ли число в заданный отрезок
- {
- bool res;
- if (d >= l.x && d <= l.y) res = true;
- else res = false;
- return res;
- }
- public static bool operator >(LineSegment l, int d)
- {
- bool res;
- /*if (d >= l.x && d <= l.y) res = true;
- else res = false;
- return res;*/
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement