private void InBox_KeyPress(object sender, KeyPressEventArgs e) { //数値およびバックスぺースのみを受け入れる if ((e.KeyChar < '0' || e.KeyChar > '9') && (e.KeyChar != '\b')) { if (e.KeyChar != '-' && InBox.TextLength == 0) { e.Handled = true; } } if ((e.KeyChar == (char)Keys.Enter) && InBox.Text != "" && InBox.Text != "-") { Console.WriteLine(InBox.Text); OutBox.AppendText(InBox.Text + "\r\n"); Kotaeawase(); InBox.Text = ""; if (mondaiCnt < mondaiMax) { Mondaisakusei(); } else { Seiseki(); } } }
private void Seiseki() { InBox.Enabled = false; mondaiLbl2.Text = "";//問題の表示をクリア OutBox.AppendText("正解数は" + seikaiCnt + "です。"); PercentageOfCorrectAnswers = seikaiCnt / mondaiMax * 100; OutBox.AppendText("正答率は" + PercentageOfCorrectAnswers + " % です。"); StartButton.Text = "開 始"; }
}//Kotaeawase // 成績処理 private void Seiseki() { mondaiCnt++; // Timer1_Tick を終了するためのプラス1 InBox.Enabled = false; // InBox を無効に MondaiLbl.Text = ""; // 問題の表示のクリア OutBox.AppendText("正解数は " + seikaiCnt + " です"); // 正解率の表示 ansRate = 1.0 * seikaiCnt / mondaiMax * 100; // C#の場合、整数同士ではなく実数同士の割り算であることを示すために、1.0 を最初にかける必要がある。 OutBoxCorrectAnsRate.Text = ansRate + " %"; }//Seiseki
private void Kotaeawase() { if (noC == Int64.Parse(InBox.Text)) { OutBox.AppendText("○ "); seikaiCnt++; } else { OutBox.AppendText("× "); } OutBox.AppendText(mondaiLbl2.Text + InBox.Text + "\r\n"); }
private void CauchyButton_Click(object sender, EventArgs e) { leftBorder = Convert.ToDouble(LeftBorderBox.Text); rightBorder = Convert.ToDouble(RightBorderBox.Text); double[] x = new Double[2]; x.SetValue(Convert.ToDouble(x0Box.Text), 0); x.SetValue(Convert.ToDouble(x1Box.Text), 1); double eps = Convert.ToDouble(EpsilonBox.Text); double h = Convert.ToDouble(StepBox.Text); OutBox.Clear(); OutBox.AppendText(Grad(x, eps, h)); }
}//InBox_KeyPress // 答え合わせ private void Kotaeawase() { // Inr64.parse() = ()内の取得した値を数値型に変換する if (sumAB == Int64.Parse(InBox.Text)) { OutBox.AppendText("〇 "); // ここで \r\n を入力しないのがポイント seikaiCnt++; // 正解数を+1 } else { // ここで \r\n を入力しないのがポイント OutBox.AppendText("× "); } // 問題 + 入力 + 改行 OutBox.AppendText(MondaiLbl.Text + InBox.Text + "\r\n"); }//Kotaeawase
private void StartButton_Click(object sender, EventArgs e) { OutBox.Clear(); List <Attribute> matrixAttr = new List <Attribute>(); int x = 0; int y = 0; double min = 0; double[,] A1; x = int.Parse(Xbox.Text); y = int.Parse(Ybox.Text); A1 = new double[x, y]; for (int i = 0, index = 0; i < x; i++) { for (int j = 0; j < y; j++, index++) { A1[i, j] = parseElement(index); } } for (int i = y - x, count = 0; i < y; count++, i++) { matrixAttr.Add(new Attribute() { value = A1[count, y - 1] }); if (i == y - 1) { matrixAttr[count].name = "P"; } else { matrixAttr[count].name = "x" + i; } } do { min = 0; int colPosition = 0; // Find min element in last line and set colPosition for (int i = 0; i < y; i++) { if (A1[x - 1, i] < 0 && min > A1[x - 1, i]) { min = A1[x - 1, i]; colPosition = i; } } double[] tempArray = new double[x - 1]; // A1[Last col] / A1[colPosition] for (int i = 0; i < tempArray.Length; i++) { tempArray[i] = A1[i, y - 1] / A1[i, colPosition]; } min = tempArray[0]; int rawPosition = 0; // Find min element and set rawPosition for (int i = 0; i < tempArray.Length; i++) { if (min > tempArray[i]) { min = tempArray[i]; rawPosition = i; } } double num = A1[rawPosition, colPosition]; // A1[rawPosition] / A1[rawPosition, colPosition] for (int i = 0; i < y; i++) { A1[rawPosition, i] = A1[rawPosition, i] / num; } // A1[raws] - A1[rawPosition] * A1[colPosition] for (int i = 0; i < x - 1; i++) { if (i != rawPosition) { num = A1[i, colPosition]; for (int j = 0; j < y; j++) { A1[i, j] = A1[i, j] - A1[rawPosition, j] * Math.Abs(num); } } } num = A1[x - 1, colPosition]; // A1[Last raw] + A1[rawPosition] * A1[colPosition] for (int i = 0; i < y; i++) { A1[x - 1, i] = A1[x - 1, i] + A1[rawPosition, i] * Math.Abs(num); } // Change values and rawPosition.name beacause of new basic solution for (int i = 0; i < x; i++) { matrixAttr[i].value = A1[i, y - 1]; if (i == rawPosition) { matrixAttr[i].name = "x" + i; } } // Repeat? min = 0; for (int i = 0; i < y; i++) { if (A1[x - 1, i] < 0 && min > A1[x - 1, i]) { min = A1[x - 1, i]; } } } while (min < 0); // Sort by Name column matrixAttr.Sort((a, b) => { if (a.name != "P" && b.name != "P") { return(a.name.CompareTo(b.name)); } return(0); }); // And print out for (int i = 0; i < x; i++) { OutBox.AppendText(matrixAttr[i].name + " = " + matrixAttr[i].value + "\n"); } }
private void Seiseki() { InBox.Enabled = false; MondaiLbl.Text = ""; OutBox.AppendText("正解数は " + seikaiCnt + " です"); }