2015年6月29日 星期一

[2015][Quiz]FinalExam_40173027H

程式分為十個部分
Form1 為視窗主程式
Ball 為球的類別
    紀錄球速.飛行距離.飛行角度.委託球的飛行狀況給裁判
BaseBallField 為球場資料類別
    紀錄球場大.小角度.委託廠地資訊給裁判
Batter 為打者類別
    紀錄打者打擊球速上限.打擊球的委託
Fielder 為防守者的父類別
    紀錄防守範圍.角度的最大.小值和接球
CenterFielder.Pitcher.SecondBaseMan 為防守者的子類別
    Pitcher較不同有多投球的委託
Umpire 為裁判的類別
    Pitcher判定好球.界外球.接殺...等等

2015年6月18日 星期四

[2015][Quiz][Week07]Quiz04 - 40173044H

[2015][Quiz][Week12]Quiz06 - Team01

[2015][Quiz][Week11]Quiz05 - Team05

[2015][Quiz][Week12]Quiz06 - Team05

主程式:Form1.cs 父類別:Shape3D 子類別:Ball,Cube,Cylinder,Pyramid 靜態類別:GeoConstant

[2015] 期末考題參考

連結

[2015][Quiz][Week12]Quiz06 - Team03

按我顯示

[2015][Quiz][Week07]Quiz04 - 40075040H

按我顯示

2015年6月17日 星期三

[2015][Quiz][Week12]Quiz06 - Team02

< !--more--> 主程式:Form1.cs
父類別:Shape3D
子類別:Ball,Cube,Cylinder,Pyramid
靜態類別:GeoConstant


Form1
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Hw6
{
    public partial class Form1 : Form
    {
        private ArrayList shapeArr=new ArrayList();
        private static double[] densityArr = { 2.7, 7.87, 11.3 };
        public Form1()
        {
            InitializeComponent();
            cbox_ShapeSelect.SelectedIndex = 0;
            cbox_MaterialSelect.SelectedIndex = 0;
        }

        private void cbox_ShapeSelect_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (cbox_ShapeSelect.SelectedIndex)
            {
                case 0:
                    lbl_Para1.Text = "半徑";
                    lbl_Para2.Visible = false;
                    txt_Para2.Visible = false;
                    break;
                case 1:
                    lbl_Para1.Text = "邊長";
                    lbl_Para2.Visible = false;
                    txt_Para2.Visible = false;
                    break;
                case 2:
                    lbl_Para1.Text = "半徑";
                    lbl_Para2.Text = "高";
                    lbl_Para2.Visible = true;
                    txt_Para2.Visible = true;
                    break;
                case 3:
                    lbl_Para1.Text = "邊長";
                    lbl_Para2.Text = "高";
                    lbl_Para2.Visible = true;
                    txt_Para2.Visible = true;
                    break;
                default:
                    break;

            }
        }

        private void btn_Add_Click(object sender, EventArgs e)
        {
            int amount = Shape3D.Amount;

            double density = densityArr[cbox_MaterialSelect.SelectedIndex];

            switch (cbox_ShapeSelect.SelectedIndex)
            {
                case 0:
                    Ball ball = new Ball(double.Parse(txt_Para1.Text), density);
                    shapeArr.Add(ball);
                    break;
                case 1:
                    Cube cube = new Cube(double.Parse(txt_Para1.Text), density);
                    shapeArr.Add(cube);
                    break;
                case 2:
                    Cylinder cylinder = new Cylinder(double.Parse(txt_Para1.Text), double.Parse(txt_Para2.Text),density);
                    shapeArr.Add(cylinder);
                    break;
                case 3:
                    Pyramid pyramid = new Pyramid(double.Parse(txt_Para1.Text), double.Parse(txt_Para2.Text), density);
                    shapeArr.Add(pyramid);
                    break;
                default:
                    break;
            }
            txt_Message.AppendText(((Shape3D)shapeArr[amount]).ShapeProperty()+Environment.NewLine);
            txt_AmountOfShape.Text = Shape3D.Amount.ToString();
        }

        private void btn_Calculate_Click(object sender, EventArgs e)
        {
            txt_Display.Clear();
            for (int i = 0; i < Shape3D.Amount;i++ )
            {
                string str = (((Shape3D)shapeArr[i]).ShowVolumeWeight() + Environment.NewLine);
                txt_Display.AppendText(str);
            }
        }
        private bool CompareByVolumeAscent(Shape3D a, Shape3D b)
        {
            if (a.Volume() > b.Volume())
                return true;
            else
                return false;

        }
        private bool CompareByVolumeDescent(Shape3D a, Shape3D b)
        {
            if (a.Volume() < b.Volume())
                return true;
            else
                return false;

        }
        private bool CompareByWeightAscent(Shape3D a, Shape3D b)
        {
            if (a.Weight() > b.Weight())
                return true;
            else
                return false;

        }
        private bool CompareByWeightDescent(Shape3D a, Shape3D b)
        {
            if (a.Weight() < b.Weight())
                return true;
            else
                return false;

        }
        private delegate bool CompareFunc(Shape3D a, Shape3D b);
        private void BubbleSort(ArrayList arr, CompareFunc cmp)
        {
            for (int i = 0; i < arr.Count; i++)
            {
                for (int j = 0; j < arr.Count - 1; j++)
                {
                    if (cmp((Shape3D)arr[j], (Shape3D)arr[j + 1]))
                    {
                        Shape3D temp;
                        temp = (Shape3D)arr[j];
                        arr[j] = arr[j + 1];
                        arr[j + 1] = temp;
                    }
                }
            }
        }
        private void Sort()
        {
            switch (cBSort.SelectedIndex)
            { 
                case 0:
                    if (rBtnAscent.Checked)
                        BubbleSort(shapeArr, CompareByWeightAscent);
                    else if (rBtnDescent.Checked)
                        BubbleSort(shapeArr, CompareByWeightDescent);
                    break;
                case 1:
                    if (rBtnAscent.Checked)
                        BubbleSort(shapeArr, CompareByVolumeAscent);
                    else if (rBtnDescent.Checked)
                        BubbleSort(shapeArr, CompareByVolumeDescent);
                    break;
            }
        }

        private void btnConcern_Click(object sender, EventArgs e)
        {
            Sort();
            txt_Display.Clear();
            for (int i = 0; i < Shape3D.Amount; i++)
            {
                string str = (((Shape3D)shapeArr[i]).ShowVolumeWeight() + Environment.NewLine);
                txt_Display.AppendText(str);
            }
        }
    }
}
Shape3D
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hw6
{
    abstract class Shape3D
    {
        protected double density;
        private static int amount = 0;
        public Shape3D()
        {
            density = 0;
            amount++;
        }
        public Shape3D(double d)
        {
            Density = d;
            amount++;
        }
        public double Density
        {
            get { return density; }
            set
            {
                if (density < 0)
                    density = 0;
                else
                    density = value;
            }
        }
        public static int Amount
        {
            get { return amount; }
        }
        public double Weight()
        {
            return Density * Volume();
        }
        //Virtual Method
        public abstract double Volume();
        
        public string ShowVolumeWeight()
        {
            string str = ShapeProperty();
            str += '\t';
            str += string.Format("{0,8:F2}", density);
            str += '\t';
            str += string.Format("{0,8:F2}", Volume());
            str += '\t';
            str += string.Format("{0,8:F2}", Weight());
            return str;
        }
        public abstract string ShapeProperty();

    }
}

Ball
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hw6
{
    class Ball : Shape3D
    {
        private double radius;
       // private static double pi = 3.1415926;
        public Ball(double radius, double density)
            : base(density)
        {
            Radius = radius;
        }
        public double Radius
        {
            get { return radius; }
            set
            {
                if (radius < 0)
                    radius = 0;
                else
                    radius = value;
            }
        }
        public override double Volume()
        {
            return 4.0/3*GeoConstant.pi*radius*radius*radius;
        }

      
        public override string ShapeProperty()
        {
            string str = string.Format("{0,8}", "Ball");
            str += '\t';
            str += string.Format("{0,8:F2}", radius);
            str += '\t';
            str += string.Format("{0,8}", "");
            return str;
        }
    }
}
Cube
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hw6
{
    class Cube : Shape3D
    {
        private double side;

        public Cube(double side, double density)
            : base(density)
        {
            Side = side;
        }
        public double Side
        {
            get { return side; }
            set
            {
                if (side < 0)
                    side = 0;
                else
                    side = value;
            }
        }
        public override double Volume()
        {
            return side*side*side;
        }


        public override string ShapeProperty()
        {
            string str = string.Format("{0,8}", "Cube");
            str += '\t';
            str += string.Format("{0,8:F2}", side);
            str += '\t';
            str += string.Format("{0,8}", "");
            return str;
        }
    }
}

Cylinder
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hw6
{
    class Cylinder : Shape3D
    {
        private double radius;
        private double height;
      //  private static double pi = 3.1415926;
        public Cylinder(double radius, double height,double density)
            : base(density)
        {
            Radius = radius;
            Height = height;
        }
        public double Radius
        {
            get { return radius; }
            set
            {
                if (radius < 0)
                    radius = 0;
                else
                    radius = value;
            }
        }
        public double Height
        {
            get { return height; }
            set
            {
                if (height < 0)
                    height = 0;
                else
                    height = value;
            }
        }
        public override double Volume()
        {
            return GeoConstant.pi * radius * radius * height;
        }


        public override string ShapeProperty()
        {
            string str = string.Format("{0,8}", "Cylinder");
            str += '\t';
            str += string.Format("{0,8:F2}", radius);
            str += '\t';
            str += string.Format("{0,8:F2}", height);
            return str;
        }
    }
}

Pyramid
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hw6
{
    class Pyramid : Shape3D
    {
        private double side;
        private double height;
        public Pyramid(double side, double height,double density)
            : base(density)
        {
            Side = side;
            Height = height;
        }
        public double Side
        {
            get { return side; }
            set
            {
                if (side < 0)
                    side = 0;
                else
                    side = value;
            }
        }
        public double Height
        {
            get { return height; }
            set
            {
                if (height < 0)
                    height = 0;
                else
                    height = value;
            }
        }
        public override double Volume()
        {
            return 1.0/3*side*side*height;
        }



        public override string ShapeProperty()
        {
            string str = string.Format("{0,8}", "Pyramid");
            str += '\t';
            str += string.Format("{0,8:F2}", side);
            str += '\t';
            str += string.Format("{0,8:F2}", height);
            return str;
        }
    }
}

GeoConstant
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hw6
{
    //靜態類別, 不能實體化物件
    static class GeoConstant
    {
        public const double pi = 3.1415926;
    }
}

[2015][Quiz][Week11]Quiz05 - Team02

2015年5月20日 星期三

[2015][Quiz][Week12]Quiz06 - Team06

程式分為七個部分
Form1 為視窗主程式.進行排序
ConstantTable 為抽象類別
    定義圓周率.金屬密度.建立密度體積重量輸出方法.虛擬計算體積方法.虛擬形狀以及參數輸出方法
Shape3D 為父類別
    產生靜態數量.形狀.材質
Ball.Cube.Cylinder.Pyramid 為子類別(繼承Shape)
    定義各形狀之參數.建立體積計算方法.形狀以及參數輸出方法

2015年5月13日 星期三

[2015][Quiz][Week11]Quiz05 - Team04

Form1.cs為視窗設計
Shape3D.cs為基礎類別
Ball.cs、Cube.cs、Cylinder.cs、Pyramid.cs為衍生類別
Constant.cs為紀錄運算需要用到的常數,例如pi

[2015][Quiz][Week11]Quiz05 - Team03

2015年5月9日 星期六

[2015][Quiz][Week11]Quiz05 - Team06

程式分為七個部分
Form1 為視窗主程式
ConstantTable 為抽象類別
    定義圓周率.金屬密度.建立密度體積重量輸出方法.虛擬計算體積方法.虛擬形狀以及參數輸出方法
Shape 為父類別
    產生靜態數量.形狀.材質
Ball.Cube.Cylinder.Pyramid 為子類別(繼承Shape)
    定義各形狀之參數.建立體積計算方法.形狀以及參數輸出方法

2015年5月7日 星期四

[2015][Homework]Team01 - Hw07

[2015][Homework]Team04 - Hw07

Form1.cs為視窗設計
Shape3D.cs為基礎類別
Ball.cs、Cube.cs、Cylinder.cs、Pyramid.cs為衍生類別
Constant.cs為紀錄運算需要用到的常數,例如pi

[2015][Homework]Team02 - Hw07

2015年5月6日 星期三

[2015][Homework]Team06 - Hw07

程式分為:
視窗進入點:Form
父類別:Shape3D
子類別:Ball,Cube,Cylinder,Pyramid

2015年4月19日 星期日

[2015][Homework]Team03 - Hw06

按我顯示

2015年4月16日 星期四

[2015][Quiz]MidExam_60373012H

按我顯示

[2015][Quiz]MidExam_40075040H

[2015][Quiz]MidExam_60373006H

[2015][Quiz]MidExam_40173038H

[Reference] MidExam

[2015][Quiz]MidExam_40173034H

程式有三部分 程式進入點 視窗程式 waterJug類別

[2015][Quiz]MidExam_40173022H

[2015][Quiz]MidExam_40073037H

Form1.cs

JugPuzzle.cs 第二題 按我顯示 按我顯示

[2015][Quiz]MidExam_40173037H

[2015][Quiz]MidExam-40173044H

[2015][Quiz]MidExam-40173007H

程式有三個部分
Program為程式進入點
Jug為視窗主程式
JugPuzzle為類別 設定容量.裝倒水功能

[2015][Quiz]MidExam - 40073049H

[2015][Quiz]MidExam - 40173032H

[2015][Quiz]MidExam - 40173041H

[2015][Quiz]MidExam - 40173027H

[2015][Quiz]MidExam-R02945022

[2015][Quiz]MidExam -40173008H

[2015][Quiz]MidExam -60373020H

第一題 Form1.cs

2015年4月11日 星期六

[2015][Quiz][Week07]Quiz04-40173008H

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Quiz4
{
    public partial class pinboard : Form
    {
        PinBoard board = new PinBoard(); //建立板子
        
        public pinboard()
        {

            InitializeComponent();
        }

        private void btn_calculate_Click(object sender, EventArgs e)
        {


            Triangle tri = new Triangle();
            int[] row = new int[3];
            int[] col = new int[3];
            col[0] = int.Parse(txtCol1.Text);
            row[0] = int.Parse(txtRow1.Text);
            col[1] = int.Parse(txtCol2.Text);
            row[1] = int.Parse(txtRow2.Text);
            col[2] = int.Parse(txtCol3.Text);
            row[2] = int.Parse(txtRow3.Text);
            for (int i = 0; i <= 2; i++)
            {
                tri.pointArray[i] = board.pinArray[row[i], col[i]];
            }
            board.SetPinsPosition();
            txtX1.Text = tri.pointArray[0].xCoordinate.ToString();
            txtY1.Text = tri.pointArray[0].yCoordinate.ToString();
            txtX2.Text = tri.pointArray[1].xCoordinate.ToString();
            txtY2.Text = tri.pointArray[1].yCoordinate.ToString();
            txtX3.Text = tri.pointArray[2].xCoordinate.ToString();
            txtY3.Text = tri.pointArray[2].yCoordinate.ToString();
            if (!tri.ConditionsOfTriangle())
                txt_Display.AppendText("以上三點無法構成三角形,重新產生三點\n");
            double Perimeter=tri.Perimeter();
            txt_Display.AppendText(DisplayStringPerimeter(Perimeter));

            double Area = tri.Area();
            txt_Display.AppendText(DisplayStringArea(Area));


            double radius = tri.RadiusOfCircumcircle();
            txt_Display.AppendText(DisplayStringradius(radius));

        }

        private string DisplayStringValue(double Value)
        {
            string StrDisplay = "";
            StrDisplay += Value;
            StrDisplay += "\n";
            return StrDisplay;
        }
        private string DisplayStringPerimeter(double Perimeter) 
        {
            string StrDisplay = "";
            StrDisplay += "周長";
            StrDisplay += Perimeter;
            StrDisplay += "\n";
            return StrDisplay;
        }
        private string DisplayStringArea(double Area)
        {
            string StrDisplay = "";
            StrDisplay += "面積";
            StrDisplay += Area;
            StrDisplay += "\n";
            return StrDisplay;
        }
        private string DisplayStringradius(double radius)
        {
            string StrDisplay = "";
            StrDisplay += "外接圓半徑";
            StrDisplay += radius;
            StrDisplay += "\n";
            return StrDisplay;
        }



        private void button1_Click(object sender, EventArgs e)
        {
            board.rows = int.Parse(txt_rows.Text);
            board.cols = int.Parse(txt_cols.Text);
            board.rowInterval = double.Parse(txt_rowInterval.Text);
            board.colInterval = double.Parse(txt_colInterval.Text);
            Triangle tri = new Triangle();   //建立三角形
            Random rand = new Random();      //產生亂數
            board.CreatePins();

            int[] row = new int[3];
            int[] col = new int[3];
            for(int i=0;i<=2;i++)
            {
                row[i] = rand.Next(board.rows); 
                col[i] = rand.Next(board.cols);
                tri.pointArray[i] = board.pinArray[row[i], col[i]];

            }


            txtCol1.Text = col[0].ToString();
            txtRow1.Text = row[0].ToString();
            txtCol2.Text = col[1].ToString();
            txtRow2.Text = row[1].ToString();
            txtCol3.Text = col[2].ToString();
            txtRow3.Text = row[2].ToString(); 

            board.SetPinsPosition();
            txtX1.Text=tri.pointArray[0].xCoordinate.ToString();
            txtY1.Text=tri.pointArray[0].yCoordinate.ToString();
            txtX2.Text=tri.pointArray[1].xCoordinate.ToString();
            txtY2.Text=tri.pointArray[1].yCoordinate.ToString();
            txtX3.Text=tri.pointArray[2].xCoordinate.ToString();
            txtY3.Text=tri.pointArray[2].yCoordinate.ToString();
            if (!tri.ConditionsOfTriangle())
                txt_Display.AppendText("以上三點無法構成三角形,重新產生三點\n");
            


        }





 



    }
}

Point

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Quiz4
{
    class Point
    {
        public double xCoordinate;
        public double yCoordinate;

        public double DistanceBetweenTwoPoints(Point pin) //計算該點和某點之間的距離
        {
            double Distance = Math.Sqrt(Math.Pow((pin.xCoordinate - this.xCoordinate), 2) + Math.Pow((pin.yCoordinate - this.yCoordinate), 2));
            return Distance;
        }
    }
}


PinBoard
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Quiz4
{
    class PinBoard
    {
        public int rows = 0;
        public int cols = 0;
        public Double rowInterval = 0;
        public Double colInterval = 0;
        public Point[,] pinArray = null;

        public void CreatePins() //產生矩陣各點之位置
        {
            pinArray = new Point[rows, cols];
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    pinArray[i, j] = new Point();

                }
            }
        }

        public void SetPinsPosition() //依行列間距計算出各點x.y之座標
        {
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    pinArray[i, j].yCoordinate = (i * rowInterval);
                    pinArray[i, j].xCoordinate = (j * colInterval);
                }
            }
        }
    }
}

Triangle
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Quiz4
{
    class Triangle
    {
        public Point[] pointArray = new Point[3]; //建立三角形的三個點

        public bool ConditionsOfTriangle()//判斷是否符合構成三角形的條件
        {
            double lengthA = pointArray[0].DistanceBetweenTwoPoints(pointArray[1]);
            double lengthB = pointArray[1].DistanceBetweenTwoPoints(pointArray[2]);
            double lengthC = pointArray[2].DistanceBetweenTwoPoints(pointArray[0]);
            double temp = 0;


            while (true)
            {
                if (lengthB > lengthA) //將lengthA變為最長邊
                {
                    temp = lengthB;
                    lengthB = lengthA;
                    lengthA = temp;
                }
                else if (lengthC > lengthB)//lengthC變為最短邊
                {
                    temp = lengthC;
                    lengthC = lengthB;
                    lengthB = temp;
                }
                else
                {
                    break;
                }
            }
            if (lengthA < (lengthB + lengthC)) //三角形兩邊和大於第三邊
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public double Perimeter() //計算三角形的周長
        {
            //由DistanceTo()計算兩點間的距離算出三角形三邊之邊長
            double lengthA = pointArray[0].DistanceBetweenTwoPoints(pointArray[1]); 
            double lengthB = pointArray[1].DistanceBetweenTwoPoints(pointArray[2]);
            double lengthC = pointArray[2].DistanceBetweenTwoPoints(pointArray[0]);

            double Perimeter = lengthA + lengthB + lengthC; 
            return Perimeter;
        }

        public double Area()
        {
            double lengthA = pointArray[0].DistanceBetweenTwoPoints(pointArray[1]); 
            double lengthB = pointArray[1].DistanceBetweenTwoPoints(pointArray[2]); 
            double lengthC = pointArray[2].DistanceBetweenTwoPoints(pointArray[0]);

            double Perimeter = lengthA + lengthB + lengthC; 
            //以海龍公式計算三角形面積
            double Area = Math.Sqrt((0.5 * Perimeter) * (0.5 * Perimeter - lengthA) * (0.5 * Perimeter - lengthB) * (0.5 * Perimeter - lengthC));
            return Area;
        }

               public double RadiusOfCircumcircle()
        {
            double lengthA = pointArray[0].DistanceBetweenTwoPoints(pointArray[1]); 
            double lengthB = pointArray[1].DistanceBetweenTwoPoints(pointArray[2]); 
            double lengthC = pointArray[2].DistanceBetweenTwoPoints(pointArray[0]);

            //由餘弦公式計算出角A之餘弦值
            double cosA = (lengthB * lengthB + lengthC * lengthC - lengthA * lengthA) / (2 * lengthB * lengthC);
            double sinA = Math.Sqrt(1 - cosA * cosA);
            //求得外接圓半徑
            double radius = 0.5 * lengthA / sinA; 
            return radius;
        }
    }
}

Program
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Quiz4
{
    static class Program
    {
        /// 
        /// 應用程式的主要進入點。
        /// 
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new pinboard());
        }
    }
}

2015年4月9日 星期四

[2015][Quiz][Week07]Quiz04-60373006H

namespace Quiz_4_9
{
    public class Point//Point 類別
    {
        public double PointX;
        public double PointY;

        //計算輸入點與成員變數的距離
        public double DistanceTo(Point Input)
        {
            return Math.Sqrt((Input.PointX - PointX) * (Input.PointX - PointX) + (Input.PointY - PointY) * (Input.PointY - PointY));
        }
    }
}
 namespace Quiz_4_9
{
    class PinBoard //釘版類別
    {

        public int Row;//列
        public int Column;//行
        public double RowInterval;
        public double ColumnInterval;
        public Point[,] PinArray;

      
        public void CreatPinArray()
        {
            PinArray = new Point[Row, Column];
            for (int i = 0; i < Row; i++)
            {
                for (int j = 0; j < Column; j++)
                    PinArray[i, j] = new Point();
            }
        }
        public void SetPointPostion()
        {
            for (int i = 0; i < Row; )
            {
                for (double ValueRow = 0; i < Row; i++, ValueRow += RowInterval)
                {
                    for (int j = 0; j < Column; )
                    {
                        for (double ValueCol = 0; j < Column; j++, ValueCol += ColumnInterval)
                        {
                            PinArray[i, j].PointX = ValueRow;
                            PinArray[i, j].PointY = ValueCol;
                        }
                    }
                }
            }
        }
    }
}
namespace Quiz_4_9
{
    class Triangle //三角形類別
    {
        //成員三點
        public Point[] PointofTriangle = new Point[3];

        public bool IsRight()
        {
            double s1 = PointofTriangle[0].DistanceTo(PointofTriangle[1]);
            double s2 = PointofTriangle[1].DistanceTo(PointofTriangle[2]);
            double s3 = PointofTriangle[0].DistanceTo(PointofTriangle[2]);
            if ((s1 + s2 > s3) && (s2 + s3 > s1) && (s1 + s3 > s2))
                return true;
            else
                return false;
        }//判斷三角形是否合法
        public double Preimeter()
        {
            double s1 = PointofTriangle[0].DistanceTo(PointofTriangle[1]);
            double s2 = PointofTriangle[1].DistanceTo(PointofTriangle[2]);
            double s3 = PointofTriangle[0].DistanceTo(PointofTriangle[2]);
            return (s1 + s2 + s3);
        }//周長
        public double Area()
        {
            double s1 = PointofTriangle[0].DistanceTo(PointofTriangle[1]);
            double s2 = PointofTriangle[1].DistanceTo(PointofTriangle[2]);
            double s3 = PointofTriangle[2].DistanceTo(PointofTriangle[0]);
            double s = (s1 + s2 + s3) / 2;
            return Math.Sqrt(s * (s - s1) * (s - s2) * (s - s3));
        }//面積
        public double RadiusOfCircumcircle()
        {
            double a = PointofTriangle[0].DistanceTo(PointofTriangle[1]);
            double b = PointofTriangle[1].DistanceTo(PointofTriangle[2]);
            double c = PointofTriangle[2].DistanceTo(PointofTriangle[0]);
            double cosAlpha = (b * b + c * c - a * a) / (2 * b * c);
            double sinAlpha = Math.Sqrt(1 - cosAlpha * cosAlpha);
            return (0.5 * a / sinAlpha);
        }//外接圓半徑
    }
}
namespace Quiz_4_9
{
    public partial class Form1 : Form
    {
        private PinBoard board;
        Triangle triangle;
        Random rand;

        public Form1()
        {
            InitializeComponent();
            board = new PinBoard();
            triangle = new Triangle();
            rand = new Random();
        }

        //btn_GenerateTriangle功能創造PinArray
        private void btn_GenerateTriangle_Click(object sender, EventArgs e)
        {
            if (txt_RowKeyin.Text != "" && txt_ColumnKeyin.Text != "" && txt_RowIntervalKeyin.Text != "" && txt_ColumnIntervalKeyin.Text != "")
            {
                //讀取txt
                board.Row = Convert.ToInt16(txt_RowKeyin.Text);
                board.Column = Convert.ToInt16(txt_ColumnKeyin.Text);
                board.RowInterval = Convert.ToDouble(txt_RowIntervalKeyin.Text);
                board.ColumnInterval = Convert.ToDouble(txt_ColumnIntervalKeyin.Text);
                //創造PinBoard
                board.CreatPinArray();
                board.SetPointPostion();
                PrintPoint();
            }
            else
                MessageBox.Show("缺參數"); 
        }

        //亂數選擇三點作為三角形,並將三點塞進Triangle類別中,同時print出來
        private void PrintPoint()
        {
            //亂數選點 && 塞進txt
            txt_Point1Row.Text = rand.Next(board.Row).ToString();
            txt_Point1Column.Text = rand.Next(board.Column).ToString();
            txt_Point2Row.Text = rand.Next(board.Row).ToString();
            txt_Point2Column.Text = rand.Next(board.Column).ToString();
            txt_Point3Row.Text = rand.Next(board.Row).ToString();
            txt_Point3Column.Text = rand.Next(board.Column).ToString();
            //用選點結果,提出PinBoard點,並塞進Triangle類別
            triangle.PointofTriangle[0] = board.PinArray[Convert.ToInt16(txt_Point1Row.Text), Convert.ToInt16(txt_Point1Column.Text)];
            triangle.PointofTriangle[1] = board.PinArray[Convert.ToInt16(txt_Point2Row.Text), Convert.ToInt16(txt_Point2Column.Text)];
            triangle.PointofTriangle[2] = board.PinArray[Convert.ToInt16(txt_Point3Row.Text), Convert.ToInt16(txt_Point3Column.Text)];
            //顯示三角形的三點
            txt_Point1X.Text = triangle.PointofTriangle[0].PointX.ToString();
            txt_Point1Y.Text = triangle.PointofTriangle[0].PointY.ToString();
            txt_Point2X.Text = triangle.PointofTriangle[1].PointX.ToString();
            txt_Point2Y.Text = triangle.PointofTriangle[1].PointY.ToString();
            txt_Point3X.Text = triangle.PointofTriangle[2].PointX.ToString();
            txt_Point3Y.Text = triangle.PointofTriangle[2].PointY.ToString();
        }

        //將Triangle類別中的數字提出來做運算,並放進txtbox裡。
        private void btn_Calulate_Click(object sender, EventArgs e)
        {
            //判斷三點是否為空
            if (txt_Point1X.Text != "" && txt_Point1Y.Text != "" && txt_Point2X.Text != "" &&
                txt_Point2Y.Text != "" && txt_Point3X.Text != "" && txt_Point3Y.Text != "")
            {//判斷手動輸入數字是否超過板子大小
                if (Convert.ToInt16(txt_Point1Row.Text) < board.Row && Convert.ToInt16(txt_Point1Column.Text) < board.Column &&
                    Convert.ToInt16(txt_Point2Row.Text) < board.Row && Convert.ToInt16(txt_Point2Column.Text) < board.Column &&
                    Convert.ToInt16(txt_Point3Row.Text) < board.Row && Convert.ToInt16(txt_Point3Column.Text) < board.Column)
                {
                    txt_ResultPrint.Text = "";
                    //為手動輸入所以必須再寫一次
                    triangle.PointofTriangle[0] = board.PinArray[Convert.ToInt16(txt_Point1Row.Text), Convert.ToInt16(txt_Point1Column.Text)];
                    triangle.PointofTriangle[1] = board.PinArray[Convert.ToInt16(txt_Point2Row.Text), Convert.ToInt16(txt_Point2Column.Text)];
                    triangle.PointofTriangle[2] = board.PinArray[Convert.ToInt16(txt_Point3Row.Text), Convert.ToInt16(txt_Point3Column.Text)];
                    if (triangle.IsRight() == true)
                    {
                        txt_ResultPrint.Text += "周長:";
                        txt_ResultPrint.Text += triangle.Preimeter().ToString() + Environment.NewLine;
                        txt_ResultPrint.Text += "面積:";
                        txt_ResultPrint.Text += triangle.Area().ToString() + Environment.NewLine;
                        txt_ResultPrint.Text += "外接圓半徑:";
                        txt_ResultPrint.Text += triangle.RadiusOfCircumcircle().ToString() + Environment.NewLine;
                    }
                    else
                        txt_ResultPrint.Text = "the triangle is illegal";
                }
                else
                    MessageBox.Show("輸入數字超過板子大小");
            }
            else
                MessageBox.Show("缺參數");
        }

    }
}

[2015][Homework]Team03 - Hw03

namespace practice
{
    class Test
    {
        static void KeyInPara(MyDateTime date)
        {
            int year;
            int month;
            int day;
            do
            {
                Console.WriteLine("輸入一個西元年份");
                year = Convert.ToInt16(Console.ReadLine());
                if (year > 0)
                    date.Year = year;
                else
                    Console.WriteLine("重新輸入");
            } while (date.Year < 0);
            do
            {
                Console.WriteLine("輸入一個西元月份");
                month = Convert.ToInt16(Console.ReadLine());
                if (month > 0)
                    date.Month = month;
                else
                    Console.WriteLine("重新輸入");
            } while (date.Month < 0);
            do
            {
                Console.WriteLine("輸入一個西元日期");
                day = Convert.ToInt16(Console.ReadLine());
                if (month > 0)
                    date.Day = day;
                else
                    Console.WriteLine("\n重新輸入");
            } while (date.Day < 0);
        }
        static void DetermineWeeks(MyDateTime date,int year, int month, int day)
        {
            Console.WriteLine("{0}/{1}/{2} : ", year,month,day);
            switch(date.DetermineWeek(year,month,day))
            {
                case 0:
                    Console.WriteLine("星期日");
                    break;
                case 1:
                    Console.WriteLine("星期一");
                    break;
                case 2:
                    Console.WriteLine("星期二");
                    break;
                case 3:
                    Console.WriteLine("星期三");
                    break;
                case 4:
                    Console.WriteLine("星期四");
                    break;
                case 5:
                    Console.WriteLine("星期五");
                    break;
                case 6:
                    Console.WriteLine("星期六");
                    break;
            }
        }
        static void Main(string[] args)
        {
            MyDateTime date = new MyDateTime();
            string iscontinue="y";
            do
            {
                KeyInPara(date);
                Console.WriteLine("====================我是分隔線====================");
                Console.WriteLine("{0}/{1}/{2}", date.Year, date.Month, date.Day);
                if (date.DetermineLeapYear(date.Year) == true)
                {
                    Console.WriteLine("{0}是閏年", date.Year);
                    Console.WriteLine("{0}年有366天", date.Year);
                }
                else
                {
                    Console.WriteLine("{0}是平年", date.Year);
                    Console.WriteLine("{0}年有365天", date.Year);
                }
                Console.WriteLine("{0}/{1}月 有{2}天", date.Year, date.Month, date.CountDayofMonth(date.Year, date.Month));
                DetermineWeeks(date, date.Year, date.Month, date.Day);
                Console.WriteLine("====================我是分隔線====================");
                Console.WriteLine("\n是否繼續(y)");
                iscontinue = Console.ReadLine();
            } while (iscontinue == "y");
            Console.WriteLine("按任意鍵結束");
            Console.ReadKey();
        }
    }
}
namespace practice
{
    class MyDateTime
    {
        public int Year;
        public int Month;
        public int Day;

        public bool DetermineLeapYear(int year)
        {
            if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) //可被4整除 && 不可被100整除 ||可被400整除
                return true;
            return false;
        }
        public int CountDayofMonth(int year, int month)
        {
            if ((1 <= month) && (month <= 12) && month != 2)
            {
                if (month <= 7)
                {
                    if ((month % 2) == 1)
                        return 31;
                    else
                        return 30;
                }
                else
                {
                    if ((month % 2) == 1)
                        return 30;
                    else
                        return 31;
                }
            }
            else
                if (DetermineLeapYear(year) == true)
                    return 29;
                else
                    return 28;
        }
        public int DetermineWeek(int year, int month, int day)
        {
            double frontofyears, behindofyear;
            double week;
            frontofyears = year / 100;
            behindofyear = year % 100;
            if (month == 1 || month == 2)
            {
                if (month == 1)
                {
                    month = 13;
                    year--;
                }
                else
                {
                    month = 14;
                    year--;
                }
            }
            week = behindofyear + Math.Floor(behindofyear / 4) + Math.Floor(frontofyears / 4) - 2 * frontofyears +
                Math.Floor((26 * ((double)month + 1)) / 10) + day - 1;
            if (week < 0)
                week = (week % 7 + 7) % 7;
            else
                week %= 7;

            if (month == 13)
            {
                month = 1;
                year++;
            }
            else 
            {
                month = 2;
                year++;
            }
            return (int)week;
        }
        public bool DetermineDayIslegal(int year,int month,int day)
        {
            if (year < 0)
                return false;
            else
                if (month < 1 || month > 12)
                    return false;
                else
                    if (day > CountDayofMonth(year, month))
                        return false;
                    else
                        return true;
        }
        public int CountDayBetweenOther(int year, int month, int day, int year2, int month2, int day2)
        {
            int sumOfDay = 0;
            for (int i = year2; year < i; i--)
            {
                if (DetermineLeapYear(year++) == true)
                    sumOfDay += 366;
                else
                    sumOfDay += 365;
            }
            for (int i = month2 - 1; i >= 1; i--)
                sumOfDay += CountDayofMonth(year2, i);
            for (int i = month - 1; i >= 1; i--)
                sumOfDay -= CountDayofMonth(year2, i);
            return sumOfDay + day2 - day - 1;
            
        }
    }
}

[2015][Quiz][Week07]Quiz04-R02945022

Program為主程式
Form1為視窗程式,包含輸入與輸出
Point為類別,計算兩點距離
PinBoard為類別,產生格點與格點座標
Triangle為類別,產生triangle三點座標,計算周長、面積與外接圓半徑

[2015][Quiz][Week07] Quiz4 - 40173027H

程式分為五個部分
Form1為視窗程式
Program為主程式
Point為類別 點的x.y座標和到另一點的距離
PinBoard為類別 板子的大小.間距.創造點和設定點的位置
Triangle為類別 三個大頭針的位置.計算是否構成三角形.其周長.面積.外接圓半徑

Form1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;



namespace Quiz4
{
    public partial class Form1 : Form
    {
        PinBoard board = new PinBoard(); //建立板子

        public Form1()
        {  
            InitializeComponent();
        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void btnTriangle_Click(object sender, EventArgs e)
        {
            Triangle tri = new Triangle();   //建立三角形
            Random rand = new Random();      //產生亂數

            board.rows = int.Parse(txtRow.Text);
            board.columns = int.Parse(txtColumn.Text);
            board.rowInterval = double.Parse(txtXInterval.Text);
            board.columnInterval = double.Parse(txtYInterval.Text);

            board.CreatePins();
            board.SetPinsPosition();

            for (int i = 0; i < 3; i++)
            {
                tri.pointArray[i] = board.pinArray[rand.Next(board.rows), rand.Next(board.columns)];         //以亂數產生三角形的三個點
            }
            txtP1Row.Text = (Convert.ToString(tri.pointArray[0].xCoordinate / board.rowInterval));
            txtP1Col.Text = (Convert.ToString(tri.pointArray[0].yCoordinate / board.columnInterval));
            txtP1XInt.Text = (Convert.ToString(tri.pointArray[0].xCoordinate));
            txtP1YInt.Text = (Convert.ToString(tri.pointArray[0].yCoordinate));
            txtP2Row.Text = (Convert.ToString(tri.pointArray[1].xCoordinate / board.rowInterval));
            txtP2Col.Text = (Convert.ToString(tri.pointArray[1].yCoordinate / board.columnInterval));
            txtP2XInt.Text = (Convert.ToString(tri.pointArray[1].xCoordinate));
            txtP2YInt.Text = (Convert.ToString(tri.pointArray[1].yCoordinate));
            txtP3Row.Text = (Convert.ToString(tri.pointArray[2].xCoordinate / board.rowInterval));
            txtP3Col.Text = (Convert.ToString(tri.pointArray[2].yCoordinate / board.columnInterval));
            txtP3XInt.Text = (Convert.ToString(tri.pointArray[2].xCoordinate));
            txtP3YInt.Text = (Convert.ToString(tri.pointArray[2].yCoordinate));
        }

        private void btnCalculate_Click(object sender, EventArgs e)
        {
            Triangle tri = new Triangle();   //建立三角形

            board.rows = int.Parse(txtRow.Text);
            board.columns = int.Parse(txtColumn.Text);
            board.rowInterval = double.Parse(txtXInterval.Text);
            board.columnInterval = double.Parse(txtYInterval.Text);

            board.CreatePins();
            board.SetPinsPosition();

            for (int i = 0; i < 3; i++)
            {
                tri.pointArray[i] = new Point(); 
            }

            tri.pointArray[0].xCoordinate = (int.Parse(txtP1Row.Text)) * board.rowInterval;
            tri.pointArray[0].yCoordinate = (int.Parse(txtP1Col.Text)) * board.columnInterval;
            tri.pointArray[1].xCoordinate = (int.Parse(txtP2Row.Text)) * board.rowInterval;
            tri.pointArray[1].yCoordinate = (int.Parse(txtP2Col.Text)) * board.columnInterval;
            tri.pointArray[2].xCoordinate = (int.Parse(txtP3Row.Text)) * board.rowInterval;
            tri.pointArray[2].yCoordinate = (int.Parse(txtP3Col.Text)) * board.columnInterval;
            txtP1XInt.Text = (Convert.ToString(tri.pointArray[0].xCoordinate));
            txtP1YInt.Text = (Convert.ToString(tri.pointArray[0].yCoordinate));
            txtP2XInt.Text = (Convert.ToString(tri.pointArray[1].xCoordinate));
            txtP2YInt.Text = (Convert.ToString(tri.pointArray[1].yCoordinate));
            txtP3XInt.Text = (Convert.ToString(tri.pointArray[2].xCoordinate));
            txtP3YInt.Text = (Convert.ToString(tri.pointArray[2].yCoordinate));

            if (tri.IsRight())
            {
                txtPrint.Text = null;
                txtPrint.AppendText("三角形的周長是:" + Convert.ToString(tri.Perimeter()) + "\n");
                txtPrint.AppendText("三角形的面積是:" + Convert.ToString(tri.Area()) + "\n");
                txtPrint.AppendText("三角形的外接圓半徑是:" + Convert.ToString(tri.RadiusOfCircumcircle()) + "\n");
            }
            else 
            {
                txtPrint.Text = null;
                txtPrint.AppendText("產生的三點不構成三角形!\n");
            }
        }

        private void lblTriXInterval_Click(object sender, EventArgs e)
        {

        }
    }
}

Program
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Quiz4
{
    static class Program
    {
        /// 
        /// 應用程式的主要進入點。
        /// 
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

Point
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Quiz4
{
    class Point
    {
        public double xCoordinate;
        public double yCoordinate;

        public double DistanceTo(Point pin) //計算該點和某點之間的距離
        {
            double Distance = Math.Sqrt(Math.Pow((pin.xCoordinate - xCoordinate), 2) + Math.Pow((pin.yCoordinate - yCoordinate), 2));
            return Distance;
        }
    }
}

PinBoard
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Quiz4
{
    class PinBoard
    {
        public int rows = 10;
        public int columns = 10;
        public Double rowInterval = 10;
        public Double columnInterval = 10;
        public Point[,] pinArray = null;

        public void CreatePins() //產生矩陣各點之位置
        {
            pinArray = new Point[rows, columns];
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    pinArray[i, j] = new Point();
                }
            }
        }

        public void SetPinsPosition() //依行列間距計算出各點x.y之座標
        {
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    pinArray[i, j].xCoordinate = (i * rowInterval);
                    pinArray[i, j].yCoordinate = (j * columnInterval);
                }
            }
        }
    }
}

Triangle
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Quiz4
{
    class Triangle
    {
        public Point[] pointArray = new Point[3]; //建立三角形的三個點

        public double Perimeter() //計算三角形的周長
        {
            double length1 = pointArray[0].DistanceTo(pointArray[1]); //由DistanceTo()計算兩點間的距離
            double length2 = pointArray[1].DistanceTo(pointArray[2]); //算出三角形三邊之邊長
            double length3 = pointArray[2].DistanceTo(pointArray[0]);

            double Perimeter = length1 + length2 + length3; //三邊和為周長
            return Perimeter;
        }

        public double Area()
        {
            double length1 = pointArray[0].DistanceTo(pointArray[1]); //由DistanceTo()計算兩點間的距離
            double length2 = pointArray[1].DistanceTo(pointArray[2]); //算出三角形三邊之邊長
            double length3 = pointArray[2].DistanceTo(pointArray[0]);

            double Perimeter = length1 + length2 + length3; //已求得三邊長度以海龍公式計算三角形面積
            double Area = Math.Sqrt((0.5 * Perimeter) * (0.5 * Perimeter - length1) * (0.5 * Perimeter - length2) * (0.5 * Perimeter - length3));
            return Area;
        }

        public bool IsRight()
        {
            double length1 = pointArray[0].DistanceTo(pointArray[1]); //由DistanceTo()計算兩點間的距離
            double length2 = pointArray[1].DistanceTo(pointArray[2]); //算出三角形三邊之邊長
            double length3 = pointArray[2].DistanceTo(pointArray[0]);
            double temp = 0;
            double copyLength1 = length1; //複製三邊邊長以便依大小排序
            double copyLength2 = length2;
            double copyLength3 = length3;

            while (true)
            {
                if (copyLength2 > copyLength1) //將copyLength1變為最長邊
                {
                    temp = copyLength2;
                    copyLength2 = copyLength1;
                    copyLength1 = temp;
                }
                else if (copyLength3 > copyLength2)
                {
                    temp = copyLength3;
                    copyLength3 = copyLength2;
                    copyLength2 = temp;
                }
                else
                {
                    break;
                }
            }
            if (copyLength1 < (copyLength2 + copyLength3)) //三角形兩邊和須大於第三邊
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public double RadiusOfCircumcircle()
        {
            double lengthA = pointArray[0].DistanceTo(pointArray[1]); //由DistanceTo()計算兩點間的距離
            double lengthB = pointArray[1].DistanceTo(pointArray[2]); //算出三角形三邊之邊長
            double lengthC = pointArray[2].DistanceTo(pointArray[0]);

            double cosAlpha = (lengthB * lengthB + lengthC * lengthC - lengthA * lengthA) / (2 * lengthB * lengthC); //由餘弦公式計算出Alpha角之餘弦值
            double sinAlpha = Math.Sqrt(1 - cosAlpha * cosAlpha); //由萬用公式計算出Alpha角之正弦值
            double radius = 0.5 * lengthA / sinAlpha; //求得外接圓半徑

            return radius;
        }
    }
}

[2015][Quiz][Week07] Quiz4 - 40173041H

程式分為 1.建立點型態 2.建立板子 3.建立三角形 4.視窗 5.主程式 點型態
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Quiz4
{
    class Point
    {
        public double xCoordinate;
        public double yCoordinate;

        public double DistanceTo(Point pin) //計算該點和某點之間的距離
        {
            double Distance = Math.Sqrt(Math.Pow((pin.xCoordinate - xCoordinate), 2) + Math.Pow((pin.yCoordinate - yCoordinate), 2));
            return Distance;
        }
    }
}
板子
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Quiz4
{
    class PinBoard
    {
        public int rows;
        public int columns;
        public Double rowInterval;
        public Double columnInterval;
        public Point[,] pinArray = null;

        public void CreatePins() //產生矩陣各點之位置
        {
            pinArray = new Point[rows, columns];
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    pinArray[i, j] = new Point();
                }
            }
        }

        public void SetPinsPosition() //依行列間距計算出各點x.y之座標
        {
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    pinArray[i, j].xCoordinate = (i * rowInterval);
                    pinArray[i, j].yCoordinate = (j * columnInterval);
                }
            }
        }
    }
}

三角形
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Quiz4
{
    class TriangleFunction
    {
        public Point[] pointArray = new Point[3]; //建立三角形的三個點

        public double Perimeter() //計算三角形的周長
        {
            double length1 = pointArray[0].DistanceTo(pointArray[1]); //由DistanceTo()計算兩點間的距離
            double length2 = pointArray[1].DistanceTo(pointArray[2]); //算出三角形三邊之邊長
            double length3 = pointArray[2].DistanceTo(pointArray[0]);

            double Perimeter = length1 + length2 + length3; //三邊和為周長
            return Perimeter;
        }

        public double Area()
        {
            double length1 = pointArray[0].DistanceTo(pointArray[1]); //由DistanceTo()計算兩點間的距離
            double length2 = pointArray[1].DistanceTo(pointArray[2]); //算出三角形三邊之邊長
            double length3 = pointArray[2].DistanceTo(pointArray[0]);

            double Perimeter = length1 + length2 + length3; //已求得三邊長度以海龍公式計算三角形面積
            double Area = Math.Sqrt((0.5 * Perimeter) * (0.5 * Perimeter - length1) * (0.5 * Perimeter - length2) * (0.5 * Perimeter - length3));
            return Area;
        }

        public bool IsRight()
        {
            double length1 = pointArray[0].DistanceTo(pointArray[1]); //由DistanceTo()計算兩點間的距離
            double length2 = pointArray[1].DistanceTo(pointArray[2]); //算出三角形三邊之邊長
            double length3 = pointArray[2].DistanceTo(pointArray[0]);
            double temp = 0;
            double copyLength1 = length1; //複製三邊邊長以便依大小排序
            double copyLength2 = length2;
            double copyLength3 = length3;

            while (true)
            {
                if (copyLength2 > copyLength1) //將copyLength1變為最長邊
                {
                    temp = copyLength2;
                    copyLength2 = copyLength1;
                    copyLength1 = temp;
                }
                else if (copyLength3 > copyLength2)
                {
                    temp = copyLength3;
                    copyLength3 = copyLength2;
                    copyLength2 = temp;
                }
                else
                {
                    break;
                }
            }
            if (copyLength1 < (copyLength2 + copyLength3)) //三角形兩邊和須大於第三邊
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public double RadiusOfCircumcircle()
        {
            double lengthA = pointArray[0].DistanceTo(pointArray[1]); //由DistanceTo()計算兩點間的距離
            double lengthB = pointArray[1].DistanceTo(pointArray[2]); //算出三角形三邊之邊長
            double lengthC = pointArray[2].DistanceTo(pointArray[0]);

            double cosAlpha = (lengthB * lengthB + lengthC * lengthC - lengthA * lengthA) / (2 * lengthB * lengthC); //由餘弦公式計算出Alpha角之餘弦值
            double sinAlpha = Math.Sqrt(1 - cosAlpha * cosAlpha); //由萬用公式計算出Alpha角之正弦值
            double radius = 0.5 * lengthA / sinAlpha; //求得外接圓半徑

            return radius;
        }
    }
}

視窗
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Quiz4
{
    public partial class Form1 : Form
    {
        PinBoard board = new PinBoard();
        public Form1()
        {
            InitializeComponent();
        }
        private void btnGenerateTriengle_Click(object sender, EventArgs e)
        {

            TriangleFunction tri = new TriangleFunction();
            Random rand = new Random();
            board.rows = int.Parse(txtRow.Text);
            board.columns = int.Parse(txtColumn.Text);
            board.rowInterval = Double.Parse(txtXInterval.Text);
            board.columnInterval = Double.Parse(txtYInterval.Text);
            int[] rowRand = new int[3];
            int[] columnRand = new int[3];
            board.CreatePins();
            board.SetPinsPosition();
        TrianglePin:
            for (int i = 0; i < 3; i++)
            {
                rowRand[i] = rand.Next(board.rows);
                columnRand[i] = rand.Next(board.columns);
                tri.pointArray[i] = board.pinArray[rowRand[i], columnRand[i]];
            }
            if (!tri.IsRight())
            {
                goto TrianglePin;
            }

            txtPoint1Row.Text = rowRand[0].ToString();
            txtPoint1Column.Text = columnRand[0].ToString();
            txtPoint2Row.Text = rowRand[1].ToString();
            txtPoint2Column.Text = columnRand[1].ToString();
            txtPoint3Row.Text = rowRand[2].ToString();
            txtPoint3Column.Text = columnRand[2].ToString();
            txtPoint1X.Text = (Double.Parse(txtPoint1Column.Text) * Double.Parse(txtXInterval.Text)).ToString();
            txtPoint1Y.Text = (Double.Parse(txtPoint1Row.Text) * Double.Parse(txtYInterval.Text)).ToString();
            txtPoint2X.Text = (Double.Parse(txtPoint2Column.Text) * Double.Parse(txtXInterval.Text)).ToString();
            txtPoint2Y.Text = (Double.Parse(txtPoint2Row.Text) * Double.Parse(txtYInterval.Text)).ToString();
            txtPoint3X.Text = (Double.Parse(txtPoint3Column.Text) * Double.Parse(txtXInterval.Text)).ToString();
            txtPoint3Y.Text = (Double.Parse(txtPoint3Row.Text) * Double.Parse(txtYInterval.Text)).ToString();
            txtTriangleSolution.Text = "周長:" + tri.Perimeter().ToString();
            txtTriangleSolution.Text += Environment.NewLine;
            txtTriangleSolution.Text += "面積:" + tri.Area().ToString();
            txtTriangleSolution.Text += Environment.NewLine;
            txtTriangleSolution.Text += "外接圓:" + tri.RadiusOfCircumcircle().ToString();
            txtTriangleSolution.Text += Environment.NewLine;
        }

        private void btnCalculate_Click(object sender, EventArgs e)
        {
            TriangleFunction tri = new TriangleFunction();
            for (int i = 0; i < 3;i++ )
            {
                tri.pointArray[i]=new Point();
            }
            board.rows = int.Parse(txtRow.Text);
            board.columns = int.Parse(txtColumn.Text);
            board.rowInterval = Double.Parse(txtXInterval.Text);
            board.columnInterval = Double.Parse(txtYInterval.Text);
            txtPoint1X.Text = (Double.Parse(txtPoint1Column.Text) * Double.Parse(txtXInterval.Text)).ToString();
            txtPoint1Y.Text = (Double.Parse(txtPoint1Row.Text) * Double.Parse(txtYInterval.Text)).ToString();
            txtPoint2X.Text = (Double.Parse(txtPoint2Column.Text) * Double.Parse(txtXInterval.Text)).ToString();
            txtPoint2Y.Text = (Double.Parse(txtPoint2Row.Text) * Double.Parse(txtYInterval.Text)).ToString();
            txtPoint3X.Text = (Double.Parse(txtPoint3Column.Text) * Double.Parse(txtXInterval.Text)).ToString();
            txtPoint3Y.Text = (Double.Parse(txtPoint3Row.Text) * Double.Parse(txtYInterval.Text)).ToString();
            tri.pointArray[0].xCoordinate = double.Parse(txtPoint1X.Text);
            tri.pointArray[0].yCoordinate = double.Parse(txtPoint1Y.Text);
            tri.pointArray[1].xCoordinate = double.Parse(txtPoint2X.Text);
            tri.pointArray[1].yCoordinate = double.Parse(txtPoint2Y.Text);
            tri.pointArray[2].xCoordinate = double.Parse(txtPoint3X.Text);
            tri.pointArray[2].yCoordinate = double.Parse(txtPoint3Y.Text);
            if (!tri.IsRight())
            {
                txtTriangleSolution.Text = "不是三角形";
            }
            else
            {
                txtTriangleSolution.Text = "周長:" + tri.Perimeter().ToString();
                txtTriangleSolution.Text += Environment.NewLine;
                txtTriangleSolution.Text += "面積:" + tri.Area().ToString();
                txtTriangleSolution.Text += Environment.NewLine;
                txtTriangleSolution.Text += "外接圓:" + tri.RadiusOfCircumcircle().ToString();
                txtTriangleSolution.Text += Environment.NewLine;
            }
        }

    }
}

主程式
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Quiz4
{
    static class Program
    {
        /// 
        /// 應用程式的主要進入點。
        /// 
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}