axeefectushka

Untitled

Oct 22nd, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.65 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4.  
  5. class Program
  6. {
  7.     class Point
  8.     {
  9.         private int[] _point = new int[3];
  10.         public Point(int x, int y, int z)
  11.         {
  12.             X = x;
  13.             Y = y;
  14.             Z = z;
  15.         }
  16.         public double _mass;
  17.         public int X
  18.         {
  19.             get => _point[0];
  20.             set => _point[0] = value;
  21.         }
  22.         public int Y
  23.         {
  24.             get => _point[1];
  25.             set => _point[1] = value;
  26.         }
  27.         public int Z
  28.         {
  29.             get => _point[2];
  30.             set => _point[2] = value;
  31.         }
  32.         public double Mass
  33.         {
  34.             get => _mass;
  35.             set => _mass = value > 0 ? value : 0;
  36.         }
  37.         public bool IsZero()
  38.         {
  39.             if (X == 0 && Y == 0 && Z == 0) return true;
  40.             else return false;
  41.         }
  42.         public double Distance(Point p)
  43.         {
  44.             double _distance = Math.Sqrt((p.X - X) * (p.X - X) + (p.Y - Y) * (p.Y - Y) + (p.Z - Z)* (p.Z - Z));
  45.             return _distance;
  46.         }
  47.     }
  48.  
  49.  
  50.     static void Main()
  51.     {
  52.         Point p1 = new Point(0, 0, 0);
  53.         Point p2 = new Point(1, 2, 3);
  54.         p1.Mass = 0.33;
  55.         p2.Mass = -0.33;
  56.         Console.WriteLine("All p1 coordinates are 0? " + p1.IsZero());
  57.         Console.WriteLine("Weight of p2 is " + p2.Mass + ", but at first it was -0.33");
  58.         Console.WriteLine("Distance between p1 and p2 is " + p1.Distance(p2));
  59.         p1.X = 3;
  60.         p1.Y = 4;
  61.         p1.Z = 1;
  62.         Console.WriteLine($"After changing, the coordinates of point p1 is ({p1.X};{p1.Y};{p1.Z})");
  63.         Console.ReadKey();
  64.     }
  65. }
Add Comment
Please, Sign In to add comment