using System; namespace march22 { public class Point { private double x, y; public Point(double x, double y) { this.x = x; this.y = y; } public double X { get { return x; } set { x = value; } } public double Y { get { return y; } set { y = value; } } public override string ToString() { return String.Format("({0:F5},{1:F5})", x, y); } } /// /// Summary description for LineSegment. /// public class LineSegment { private Point[] pts; public LineSegment(Point pa, Point pb) { pts = new Point[2]; pts[0] = pa; pts[1] = pb; } public double Length() { double a = pts[1].X - pts[0].X; double b = pts[1].Y - pts[0].Y; return Math.Sqrt(a*a + b*b); } public Point MidPoint() { double x = (pts[1].X + pts[0].X)/2.0; double y = (pts[1].Y + pts[0].Y)/2.0; Point pm = new Point(x, y); return pm; } public static void Main() { Point[] pa = new Point[2]; pa[0] = new Point(-2.0, 4.0); pa[1] = new Point(9.0, 7.0); LineSegment l = new LineSegment(pa[0], pa[1]); Console.WriteLine("Two points: "+pa[0]+pa[1]); Console.WriteLine("Length = "+l.Length()); Console.WriteLine("Middle point: "+l.MidPoint()); } } }