求矩形边长,面积及周长(c#实现)

来源:互联网 发布:mysql 列表 查询优化 编辑:程序博客网 时间:2024/05/16 18:09
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{    class CPoint    {        public int x, y;        public CPoint()        { }        public CPoint(int x, int y)        {            this.x = x;            this.y = y;        }    }    class CLine:CPoint    {        public static double Getlength(CPoint p1,CPoint p2)        {            return Math.Sqrt ((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));        }    }    class CRect : CLine    {                public static double Getarea(CPoint p1,CPoint p2,CPoint p3)        {            return  (Getlength(p1,p2)*Getlength(p2,p3));        }        public static double Getzc(CPoint p1,CPoint p2,CPoint p3)        {            return (2*(Getlength(p1,p2)+Getlength(p2,p3)));        }    }    class Program    {        static void Main(string[] args)        {            CPoint a = new CPoint(2,3);            CPoint b = new CPoint(4,5);            CPoint c = new CPoint(1,3);            Console.WriteLine("距离{0},面积{1},长度{2}",CLine.Getlength(a,b),CRect.Getarea(a,b,c),CRect.Getzc(a,b,c));            Console.ReadKey();        }    }}

写的有些繁琐,而且有个比较大缺陷就是用户不能直接输入三个点的值,不太好。
0 0
原创粉丝点击