编写Point类,包括横坐标,纵坐标俩个字段和计算到另一个点距离的方法

编写Point类,包括横坐标,纵坐标俩个字段和计算到另一个点距离的方法

img


public class Point
    {
        double x1;
        double x2;
        double y1;
        double y2;
        double dis;
        public Point(double a, double b, double c, double d)
        {
            this.x1 = a;
            this.y1 = b;
            this.x2 = c;
            this.y2 = d;
        }
        public void distance()
        {
            dis = Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
            Console.WriteLine("第一个点坐标为" + x1 + "  " + y1);
            Console.WriteLine("第一个点坐标为" + x2 + "  " + y2);
            Console.WriteLine("x y两点之间距离为" + dis);
        }

    }

    class Program
    {
        static void Main(string[] args)
        {
            Point p = new Point(0, 3.0, 0, 4.0);
            p.distance();

        }
    }