Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- namespace ConsoleApplication1
- {
- class Point
- {
- private int x;
- private int y;
- public Point()
- {
- x = 0;
- y = 0;
- }
- public Point(int x, int y)
- {
- this.x = x;
- this.y = y;
- }
- public void Show()
- {
- Console.WriteLine("Point: ({0}, {1})", x, y);
- }
- public double Distance()
- {
- return Math.Sqrt(x * x + y * y);
- }
- public void Move(int a, int b)
- {
- x += a;
- y += b;
- }
- public int X
- {
- get {
- return x;
- }
- set {
- x = value;
- }
- }
- public int Y
- {
- get
- {
- return y;
- }
- set
- {
- y = value;
- }
- }
- public int ScalarMult
- {
- set
- {
- x *= value;
- y *= value;
- }
- }
- public int this[int i] {
- get
- {
- if (i == 0)
- return x;
- else
- {
- if (i == 1)
- return y;
- else
- {
- Console.WriteLine("Недопустимый индекс");
- return 0;
- }
- }
- }
- set
- {
- if (i == 0)
- x = value;
- else
- {
- if (i == 1)
- y = value;
- else
- {
- Console.WriteLine("Недопустимый индекс");
- }
- }
- }
- }
- public static Point operator++(Point a) {
- Point temp = new Point();
- temp[0] = a[0] + 1;
- temp[1] = a[1] + 1;
- return temp;
- }
- public static Point operator --(Point a)
- {
- Point temp = new Point();
- temp[0] = a[0] - 1;
- temp[1] = a[1] - 1;
- return temp;
- }
- public static bool operator true(Point a)
- {
- if (a[0] == a[1])
- return true;
- else
- return false;
- }
- public static bool operator false(Point a)
- {
- if (a[0] != a[1])
- return true;
- else
- return false;
- }
- public static Point operator+(Point a, int b)
- {
- a[0] += b;
- a[1] += b;
- return a;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Point point1 = new Point();
- Point point2 = new Point(3, 2);
- point1.Show();
- Console.WriteLine("Point 2 distance: {0}", point2.Distance());
- point1.Move(5, 5);
- point1.Show();
- point2.X = 10;
- point2.Y = 4;
- point1.ScalarMult = 3;
- point1.Show();
- point2.Show();
- Console.WriteLine("Point 1 first coordinate: {0}", point1[0]);
- Console.WriteLine("Point 2 second coordinate: {0}", point2[1]);
- point1++;
- point1.Show();
- point2--;
- point2.Show();
- if (point1)
- {
- Console.WriteLine("First and second coordinate are equals");
- }
- point2 = point2 + 5;
- point2.Show();
- }
- }
- }
Add Comment
Please, Sign In to add comment