Esempio n. 1
0
        static void Main(string[] args)
        {
            //输入A点坐标
            Console.Write("点A");
            int    x1 = 1;
            int    y1 = 1;
            CPoint p1 = new CPoint(x1, y1);

            p1.Dispaly();//打印出点

            Console.Write("到");

            //输入B点坐标
            Console.Write("点B");
            int    x2 = 6;
            int    y2 = 6;
            CPoint p2 = new CPoint(x2, y2);

            p2.Dispaly();//打印出点
            Console.Write("的距离:");

            //两点的距离
            CLine l   = new CLine(p1, p2);
            float dis = l.Distance();

            Console.WriteLine("{0:F3}。", dis);//:F3指保留三位小数。

            //矩形的周长
            int    x3 = 8, y3 = 8;
            int    x4 = 10, y4 = 10;
            CPoint p3 = new CPoint(x3, y3);
            CPoint p4 = new CPoint(x4, y4);

            CLine l1 = new CLine(p1, p2);
            CLine l2 = new CLine(p3, p4);

            CRect peri      = new CRect(l1, l2);
            float perimeter = peri.Perimeter();

            Console.WriteLine("矩形的周长:{0}", perimeter);

            //矩形的面积
            float area = peri.Area();

            Console.WriteLine("矩形的面积:{0}", area);
            Console.ReadKey();
        }
Esempio n. 2
0
 public CLine(CPoint p1, CPoint p2)
 {
     this.p1 = p1;
     this.p2 = p2;
 }