Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Point
- {
- double x;
- double y;
- public double X
- {
- get { return x; }
- set
- {
- x = value;
- }
- }
- public double Y
- {
- get { return y; }
- set
- {
- y = value;
- }
- }
- public Point(double x, double y)
- {
- X = x;
- Y = y;
- }
- public Point()
- {
- X = 0;
- Y = 0;
- }
- public Point(Point a)
- {
- X = a.X;
- Y = a.Y;
- }
- public override string ToString()
- {
- return "Точка с координатами " + X.ToString() + " и " + Y.ToString();
- }
- public static Point operator --(Point a)
- {
- a.X -= 1;
- a.Y -= 1;
- return a;
- }
- public static Point operator -(Point a)
- {
- Point b = new Point(a);
- double t = b.X;
- b.X = b.Y;
- b.Y = t;
- return b;
- }
- public static implicit operator int (Point a) // неявное преобразование
- {
- return (int)a.X;
- }
- public static explicit operator double(Point a) // явное преобразование
- {
- return a.Y;
- }
- public static Point operator -(Point a, int d)
- {
- Point b = new Point(a);
- b.Y -= d;
- return b;
- }
- public static Point operator -(int d, Point a )
- {
- Point b = new Point(a);
- b.X -= d;
- return b;
- }
- public static double operator -(Point a, Point b)
- {
- return Math.Sqrt ((a.X-b.X)* (a.X - b.X) + (a.Y - b.Y)* (a.Y - b.Y));
- }
- }
- using System;
- namespace labLangProgram_trim4_2
- {
- class Program
- {
- static void Main(string[] args)
- {
- Point p = new Point(3.1, 4.2);
- Console.WriteLine(p.ToString());
- Console.WriteLine((p--).ToString());
- Console.WriteLine((-p).ToString());
- Console.WriteLine(p.ToString());
- Console.WriteLine((double)p);
- Console.WriteLine(p+0);
- Console.WriteLine((p - 22).ToString());
- Console.WriteLine((22 - p).ToString());
- Point p2 = new Point(p);
- p2.X = 222;
- Console.WriteLine((p2 - p).ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement