Класс Point и методы для него - C#
Формулировка задачи:
Нужно добавить методы:
• определения, какая из точек ближе к началу координат,
• определения точки, являющейся серединой отрезка для двух заданных точек.
public class Point
{
private double x;
private double y;
public Point()
{
}
public Point(double x, double y)
{
this.x = x;
this.y = y;
}
public void Show()
{
Console.WriteLine("Значение x: {0}", this.x );
Console.WriteLine("Значение y: {0}", this.y );
}
public double sadaniex
{
get
{
return this.x;
}
set
{
if (this.x != value)
this.x = value;
}
}
public double sadaniey
{
get
{
return this.y;
}
set
{
if (this.y != value)
this.y = value;
}
}
public double Rasstoznie()
{
return Math.Sqrt(x * x + y * y);
}Решение задачи: «Класс Point и методы для него»
textual
Листинг программы
public static Point FindCenter(Point pt1, Point pt2)
{
Point pt=new Point((pt1.x+pt2.x)/2, (pt1.y+pt2.y)/2);
return pt;
}