public void TimesTable_Ctor_Test(int size, int val)
        {
            var target = new TimesTable(size);

            Assert.IsNotNull(target);
            Assert.IsNotNull(target.Result);
            Assert.IsTrue(target.Result.Length > 0);
            Assert.AreEqual(val, target.Result[size - 1, size - 1]);
        }
    public static void Main1()
    {
        //2차원배열 생성방법
        //int[,] arr = new int[2,3];
        //arr[0,0]=10;
        //Console.WriteLine(arr[0,0]);

        TimesTable tt = new TimesTable();

        Console.WriteLine(tt[9, 9]);
        Console.WriteLine(tt[9.9, 9.9]);

        II i = new II();

        i.val = 10;
        Console.WriteLine(i);   //이걸로 val을 찍고싶다. writeline은 인자로 전달된 객체에 대해 ToString멤버 메서드를 호출한다. 따라서 ToString을 오버로딩한다.
    }
示例#3
0
            public static void MainMenu()
            {
                WriteLine("Welcome to the Math assignment in C Sharp!");
                WriteLine("Enter 1 to build a rectangle, 2 for a square, 3 for a triangle, 4 for an octagon or 5 for a times table.");
                WriteLine("Or enter 0 to exit.");
                var answer = ReadLine();

                if (answer == "0")
                {
                    WriteLine("Goodbye!");
                    Environment.Exit(0);
                }
                else if (answer == "1")
                {
                    WriteLine("Enter the length of your rectangle: ");
                    double length = 0;
                    double width  = 0;
                    try
                    {
                        length = Convert.ToDouble(ReadLine());
                    }
                    catch (SystemException)
                    {
                        WriteLine("Error! Invalid value. Going back to main menu...");
                        Menu.MainMenu();
                    }
                    WriteLine("Enter the width of your rectangle: ");
                    try
                    {
                        width = Convert.ToDouble(ReadLine());
                    }
                    catch (SystemException)
                    {
                        WriteLine("Error! Invalid value. Going back to main menu...");
                        Menu.MainMenu();
                    }

                    Rectangle rectangle = new Rectangle(length, width);

                    WriteLine("The area of your rectangle is " + rectangle.GetArea());
                    rectangle.AcceptDetails();
                    rectangle.Display();
                    rectangle.DisplayInfo();
                    Menu.MainMenu();
                }
                else if (answer == "2")
                {
                    WriteLine("Enter the length and width of your square: ");
                    double length = 0;
                    try
                    {
                        length = Convert.ToDouble(ReadLine());
                    }
                    catch (SystemException)
                    {
                        WriteLine("Error. Invalid value specified. Returning to main menu...");
                        Menu.MainMenu();
                    }

                    var width = length;

                    Square square = new Square(length, width);

                    WriteLine("The area of your rectangle is " + square.GetArea());
                    square.AcceptDetails();
                    square.Display();
                    Menu.MainMenu();
                }
                else if (answer == "3")
                {
                    WriteLine("Enter the length of your triangle: ");
                    double length = 0;
                    double width  = 0;
                    try
                    {
                        length = Convert.ToDouble(ReadLine());
                    }
                    catch (SystemException)
                    {
                        WriteLine("Error! Invalid value. Going back to main menu...");
                        Menu.MainMenu();
                    }
                    WriteLine("Enter the width of your triangle: ");
                    try
                    {
                        width = Convert.ToDouble(ReadLine());
                    }
                    catch (SystemException)
                    {
                        WriteLine("Error! Invalid value. Going back to main menu...");
                        Menu.MainMenu();
                    }

                    Triangle triangle = new Triangle(length, width);

                    WriteLine("The area of your triangle is " + triangle.GetArea());
                    triangle.AcceptDetails();
                    triangle.Display();
                    Menu.MainMenu();
                }
                else if (answer == "4")
                {
                    WriteLine("Enter the side length of your octagon: ");
                    double sidelength = 0;
                    try
                    {
                        sidelength = Convert.ToDouble(ReadLine());
                    }
                    catch (SystemException)
                    {
                        WriteLine("Error! Invalid value. Going back to main menu...");
                        Menu.MainMenu();
                    }

                    Octagon octagon = new Octagon(sidelength);

                    octagon.AcceptDetails();
                    octagon.Display();
                    Menu.MainMenu();
                }
                else if (answer == "5")
                {
                    WriteLine("Please enter your value for a times table.");
                    double value = 0;
                    try
                    {
                        value = Convert.ToDouble(ReadLine());
                    }
                    catch (SystemException)
                    {
                    }
                    TimesTable table = new TimesTable(value);
                    table.Display();
                    Menu.MainMenu();
                }
                else
                {
                    WriteLine("Invalid response! Try again.");
                    Menu.MainMenu();
                }
            }
示例#4
0
        private void ImportTimesButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter = "Text (*.txt)|*.txt";
            dialog.Title  = "Load times";
            dialog.ShowDialog();
            string path      = dialog.FileName;
            string shortPath = Path.GetFileName(path);

            FileNameLabel.Text = shortPath;
            if (path.Equals(""))
            {
                return;
            }
            StreamReader reader     = new StreamReader(path);
            string       timeString = reader.ReadToEnd();

            reader.Close();
            var times = timeString.Split(',');

            Times       = new List <double>();
            SortedTimes = new List <double>();
            int i = 0;

            try
            {
                for (int k = 0; k < times.Length; k++)
                {
                    i = k;
                    string str = times[k].Trim();
                    if (str.EndsWith("+"))
                    {
                        str = str.Substring(0, str.Length - 1);
                    }
                    double d = double.Parse(str);
                    Times.Add(d);
                    SortedTimes.Add(d);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("File is in the wrong format " + i, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Times       = null;
                SortedTimes = null;
                return;
            }
            SortedTimes.Sort();

            TimesTable.SuspendLayout();
            SortedTimesTable.SuspendLayout();

            TimesTable.Controls.Clear();
            SortedTimesTable.Controls.Clear();

            TimesTable.RowCount       = Times.Count;
            SortedTimesTable.RowCount = Times.Count;
            for (int k = 0; k < Times.Count; k++)
            {
                TimesTable.Controls.Add(new Label()
                {
                    Text = (k + 1).ToString(), Font = new Font(FontFamily.GenericSansSerif, 14), Width = 70
                }, 0, k);
                TimesTable.Controls.Add(new Label()
                {
                    Text = Times[k].ToString(), Font = new Font(FontFamily.GenericSansSerif, 14), Width = 120
                }, 1, k);
                SortedTimesTable.Controls.Add(new Label()
                {
                    Text = (k + 1).ToString(), Font = new Font(FontFamily.GenericSansSerif, 14), Width = 70
                }, 0, k);
                SortedTimesTable.Controls.Add(new Label()
                {
                    Text = SortedTimes[k].ToString(), Font = new Font(FontFamily.GenericSansSerif, 14), Width = 120
                }, 1, k);
            }

            TimesTable.ResumeLayout();
            SortedTimesTable.ResumeLayout();
            Update();

            SummaryTable.SuspendLayout();
            SummaryTable.Controls.Clear();
            for (int k = 0; k < 5; k++)
            {
                SummaryTable.Controls.Add(new Label()
                {
                    Text = (20 * k + 10 + "%"), Font = new Font(FontFamily.GenericSansSerif, 14), Width = 70
                }, k, 0);
                SummaryTable.Controls.Add(new Label()
                {
                    Text = CalcTime(20 * k + 10).ToString(), Font = new Font(FontFamily.GenericSansSerif, 14), Width = 70
                }, k, 1);
            }
            SummaryTable.ResumeLayout();

            MeanLabel.Text    = calcMean().ToString("F2");
            AverageLabel.Text = calcAverage(0, Times.Count).ToString("F2");
            MedianLabel.Text  = SortedTimes[SortedTimes.Count / 2].ToString();
            CountLabel.Text   = Times.Count.ToString();

            ConsecutiveLabel.Text = "";

            // averages
            Ao5List   = new List <double>();
            Ao12List  = new List <double>();
            Ao100List = new List <double>();
            for (int k = 0; k + 5 <= Times.Count; k++)
            {
                Ao5List.Add(CalcAo5(k));
            }
            for (int k = 0; k + 12 <= Times.Count; k++)
            {
                Ao12List.Add(CalcAo12(k));
            }
            InitializeAo100List();

            if (Times.Count >= 5)
            {
                Ao5Label.Text = Ao5List.Min().ToString("F2");
            }
            else
            {
                Ao5Label.Text = "N/A";
            }
            if (Times.Count >= 12)
            {
                Ao12Label.Text = Ao12List.Min().ToString("F2");
            }
            else
            {
                Ao12Label.Text = "N/A";
            }
            if (Times.Count >= 100)
            {
                Ao100Label.Text = Ao100List.Min().ToString("F2");
            }
            else
            {
                Ao100Label.Text = "N/A";
            }
            StdDevLabel.Text = CalcStdDev().ToString("F2");
        }