מחלקות
מחלקות
class Points
{
static void Main(string[] args)
{
double t;
Point a = new Point(43, 7);
Point b = new Point(5, 5);
Console.WriteLine(a);
Console.WriteLine(b);
Console.WriteLine("insert new x of 2 points");
t = b.GetX();
b.SetX(a.GetX());
a.SetX(t);
Console.WriteLine(a);
Console.WriteLine(b);
Point m = new Point();
m = a.Middle(b);
Console.WriteLine(m);
}
}
}
class Point
{
private double x;
private double y;
public Point()
{
x = 0;
y = 0;
}
public Point(double x, double y)
{
this.x = x;
this.y = y;
}
public double GetX()
{
return x;
}
public double GetY()
{
return y;
}
public void SetX(double x)
{
this.x = x;
}
public void SetY(double y)
{
this.y = y;
}
public override string ToString()
{
return ("(" + this.x + "," + this.y + ")");
}
public double Distance(Point a)
{
double d = Math.Sqrt(Math.Pow((this.x - a.x),2) +
Math.Pow((this.y - a.y),2));
return d;
}
public Point Middle(Point a)
{
Point m = new Point((this.x + a.x) / 2, (this.y + a.y) /
2);
return m;
}
}
}