using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public class Vector
{
double x, y;
public void Input()
{
Console.WriteLine("Enter x:");
x = double.Parse(Console.ReadLine()); //parse - преобразует строку в число, т.е. string в double (или в int, если int.Parse)
Console.WriteLine("Enter y:");
y = double.Parse(Console.ReadLine());
}
public Vector()
{
x = 0;
y = 0;
}
public Vector(double xx, double yy)
{
x = xx;
y = yy;
}
public static Vector operator +(Vector a, Vector b) //оператор +
{
Vector c = new Vector();
c.x = a.x + b.x;
c.y = a.y + b.y;
return c;
}
public static Vector operator -(Vector a, Vector b)
{
Vector c = new Vector();
c.x = a.x - b.x;
c.y = a.y - b.y;
return c;
}
public static double operator* (Vector a, Vector b)//скалярное произведение
{
Double w = new double();
w = a.x * b.x + a.y * b.y;
return w;
}
public static Vector operator* (Vector a, double p) //умножение вектора на число
{
Vector c = new Vector();
c.x = a.x * p;
c.y = a.y * p;
return c;
}
public static Vector operator * (double p, Vector a) //умножение вектора на число
{
Vector c = new Vector();
c.x = p*a.x;
c.y = p*a.y;
return c;
}
public static Vector operator ++(Vector a) //+1 к карме вектора
{
a.x++;
a.y++;
return a;
}
public static double operator !(Vector a){ //Длина вектора
double t=Math.Sqrt(a.x*a.x+a.y*a.y);
return t;
}
public static bool operator >(Vector a, Vector b)
{
if (!a < !b) return false;
else
if (!a == !b) return false;
else return true;
}
public static bool operator <(Vector a, Vector b)
{
if (!a > !b) return false;
else
if (!a == !b) return false;
else return true;
}
public void Output()
{
Console.WriteLine("(" + x + "," + y + ")");
}
}
class Program
{
static void Main(string[] args)
{
Vector vector;
vector = new Vector();
vector.Input();
vector.Output();
Vector m, n;
m = new Vector(5, 2);
n = new Vector(-3, 7);
Vector k;
k = m + n;
k.Output();
Vector d;
d = m - n;
d.Output();
double g;
g = m * n;
Console.WriteLine(g);
++d;
d.Output();
double t=!d;
Console.WriteLine(t);
Console.WriteLine();
Vector[] vecs = new Vector[10]; //написать программу сортировки массива, сравнения массивов
for (int i= 0; i < 10; i++)
vecs[i] = new Vector();
Console.WriteLine ("Press any key to continue");
Console.ReadKey();
}
}
}