2015年11月14日 星期六

C9_4 Triangle.cs 三角形類別

using System;
namespace C9_4
{
    ///
    ///定義普通三角形做為其他三角形的基底類別
    ///
    public class Triangle : Shape
    {
        //三角形三條邊
        protected int a;
        protected int b;
        protected int c;
        public Triangle(int ta, int tb, int tc)
        {
            a = ta;
            b = tb;
            c = tc;
        }
        public override int GetArea()
        {
            int s = (a + b + c) / 2;
            int area = (int)(Math.Sqrt(s * (s-a) * (s-b) * (s-c)));
            return area;

        }
    }
}

沒有留言: