Advertisement
VladSmirN

lab2_proglang

Oct 20th, 2021
934
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.67 KB | None | 0 0
  1.  class Point
  2.     {
  3.         double x;
  4.         double y;
  5.         public double X
  6.         {
  7.             get { return x; }
  8.             set
  9.             {
  10.  
  11.                 x = value;
  12.             }
  13.  
  14.         }
  15.         public double Y
  16.         {
  17.             get { return y; }
  18.             set
  19.             {
  20.                 y = value;
  21.             }
  22.  
  23.         }
  24.         public Point(double x, double y)
  25.         {
  26.             X = x;
  27.             Y = y;
  28.  
  29.  
  30.         }
  31.         public Point()
  32.         {
  33.             X = 0;
  34.             Y = 0;
  35.         }
  36.  
  37.         public Point(Point a)
  38.         {
  39.             X = a.X;
  40.             Y = a.Y;
  41.          
  42.         }
  43.         public override string ToString()
  44.         {
  45.            
  46.             return "Точка с координатами " + X.ToString() + " и " + Y.ToString();
  47.  
  48.         }
  49.        
  50.         public static Point operator --(Point a)  
  51.         {
  52.             a.X -= 1;
  53.             a.Y -= 1;
  54.             return a;
  55.         }
  56.         public static Point operator -(Point a)
  57.         {
  58.             Point b = new Point(a);
  59.             double t = b.X;
  60.             b.X = b.Y;
  61.             b.Y = t;
  62.             return b;
  63.         }
  64.         public static implicit operator int (Point a) // неявное преобразование
  65.         {
  66.             return (int)a.X;
  67.         }
  68.         public static explicit operator double(Point a) // явное преобразование
  69.         {
  70.             return a.Y;
  71.         }
  72.         public static Point operator -(Point a, int d)  
  73.         {
  74.             Point b = new Point(a);
  75.             b.Y -= d;
  76.             return b;
  77.         }
  78.         public static Point operator -(int d, Point a )
  79.         {
  80.             Point b = new Point(a);
  81.             b.X -= d;
  82.             return b;
  83.         }
  84.         public static double operator -(Point a, Point b)
  85.         {
  86.              
  87.             return Math.Sqrt ((a.X-b.X)* (a.X - b.X) + (a.Y - b.Y)* (a.Y - b.Y));
  88.         }
  89.        
  90.     }
  91.  
  92. using System;
  93.  
  94. namespace labLangProgram_trim4_2
  95. {
  96.     class Program
  97.     {
  98.         static void Main(string[] args)
  99.         {
  100.             Point p = new Point(3.1, 4.2);
  101.             Console.WriteLine(p.ToString());
  102.             Console.WriteLine((p--).ToString());
  103.             Console.WriteLine((-p).ToString());
  104.             Console.WriteLine(p.ToString());
  105.             Console.WriteLine((double)p);
  106.             Console.WriteLine(p+0);
  107.  
  108.             Console.WriteLine((p - 22).ToString());
  109.             Console.WriteLine((22  - p).ToString());
  110.             Point p2 = new Point(p);
  111.             p2.X = 222;
  112.             Console.WriteLine((p2 - p).ToString());
  113.         }
  114.     }
  115. }
  116.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement