private void ShowAnswerPage() { List <RealNum> exp = new List <RealNum>(); BaseEquation equ = new BaseEquation(); exp = equ.MakeEasyH1(inputBox.Text); exp = equ.MakeEasyM1(exp); exp = equ.MakeEasyM2(exp); int a = (int)EquationTools.GetFrontByTimes(exp, 2); int b = (int)EquationTools.GetFrontByTimes(exp, 1); int c = (int)EquationTools.GetFrontByTimes(exp, 0); int XDown = 2 * (int)a; if (b * b - 4 * a * c < 0) { showInformation("Error", "b*b-4*a*c<0"); return; } //¡Ì string answer = new Trans().GetX(a, b, c); answer = answer.Replace("¡Ì", "√"); txt_AnswerTextBlock.Text = answer; /* fraction fa = new fraction(a); * fraction fb = new fraction(b); * fraction fc = new fraction(c); * fraction diat = new fraction(b * b - 4 * a * c); * diat.numsqrt(); * fraction x1 = (-fb + diat) / (new fraction("2") * fa); * fraction x2 = (-fb - diat) / (new fraction("2") * fa); * txt_AnswerTextBlock.Text = "x1:" + x1.ToString() + "\n"; * txt_AnswerTextBlock.Text += "x2:" + x2.ToString();*/ }
private void btn_Count_Click(object sender, RoutedEventArgs e) { txt_AnswerTextBlock.Text = ""; BaseEquation equ = new BaseEquation(); if (!equ.Checker(inputBox.Text)) { return; } if (inputBox.Text.Length == 0) { return; } List <RealNum> Exp = new List <RealNum>(equ.MakeEasyH1(inputBox.Text)); if (Exp[Exp.Count - 1].times == 2 && Data.localSettings.Values["RealMode"].ToString() == "on") { ShowAnswerPage(); return; } List <float> xValue = new List <float>(); xValue = equ.Getxvalue(inputBox.Text); for (int i = 0; i < xValue.Count; i++) { txt_AnswerTextBlock.Text += " x" + i + "=" + xValue[i] + " "; } }
private void textBox1_TextChanged(object sender, TextChangedEventArgs e) { if (console_mode) { BaseEquation be = new BaseEquation(textBox1.Text); GUIMethod = be.method; textBoxInput.Text = ExpressionTranslate.get_GUI(be); if (textBoxInput.Text != "") { textBoxInputOld = textBoxInput.Text; } } }
private void btn_Count_Click(object sender, RoutedEventArgs e) { txt_AnswerTextBlock.Text = ""; ExpressionHandle hl = new ExpressionHandle(); List <RealNum> ListExp = new List <RealNum>(); BaseEquation eqtools = new BaseEquation(); if (!eqtools.BalanceChecker(inputBox.Text)) { showInformation("ERROR", "表达式括号不平衡"); return; } ListExp = hl.MakeEasy(inputBox.Text); string result = GetResult(ListExp); txt_AnswerTextBlock.Text = result; }
private void textBoxInput_TextChanged(object sender, TextChangedEventArgs e) { //TODO:检查输入太长或太高 if (!console_mode) { //为乘法匹配行数 if (GUIMethod == BaseEquation.METHOD.MUL) { mul_special(); } if (human_changing) { int checkans = ExpressionTranslate.textGUI(textBoxInput.Text); if (checkans != 0) { if (checkans == 2) { MessageBox.Show("GUI输入不合规范,已退回上一步\r\n请检查:\r\n某行太长,最长仅限" + ExpressionTranslate.LENTH_MAX + "字符,超长请使用控制台输入方式"); } else if (checkans == 3) { MessageBox.Show("GUI输入不合规范,已退回上一步\r\n请检查:\r\n行数太多,最长仅限" + ExpressionTranslate.HEIGHT_MAX + "行,超高请使用控制台输入方式"); } else { MessageBox.Show("GUI输入不合规范,已退回上一步\r\n请检查:\r\n数字和字母超过了10个\r\n插入了非法符\r\n删除了重要字符\r\n算式行数不对"); } human_changing = false; textBoxInput.Text = textBoxInputOld; human_changing = true; } } BaseEquation be = ExpressionTranslate.get_console(textBoxInput.Text); if (be != null) { textBox1.Text = be.equation_console; } else { textBox1.Text = ""; } textBoxInputOld = textBoxInput.Text; } }
public string WorkOut(string exp) { List <float> ret = new List <float>(); BaseEquation et = new BaseEquation(); string frontPart = CutString_front(exp); string backPart = CutString_back(exp); string IChar = GetOPC(exp); string oppChar; oppChar = GetOPPChar(IChar); if (oppChar == "ERROR") { showInformation("ERROR", "不支持此类不等式"); return(oppChar); } List <RealNum> frontList = et.MakeEasy(frontPart); List <RealNum> lastList = et.MakeEasy(backPart); List <RealNum> endList; endList = et.EquationExpHandle(frontList, lastList); int MaxTimes = et.MaxTimes(endList); if (MaxTimes == 1) { if (endList[1].front == 0) { ret.Add(0); return("NO FOUND"); } ret.Add(-endList[0].front / endList[1].front); if (endList[endList.Count - 1].front < 0) { return("x" + oppChar + ret[0].ToString()); } else { return("x" + IChar + ret[0].ToString()); } } else if (MaxTimes > 2 || MaxTimes < 1) { showInformation("抱歉", "由于能力问题。我们只设计了二次不等式和一次不等式."); } else if (MaxTimes == 2) { bool haveEq = false; float[] frontNumContainer = new float[3]; #region 预处理 if (IChar[IChar.Length - 1] == '=') { haveEq = true; } for (int i = 0; i < 3; i++) { frontNumContainer[i] = 0; } foreach (var ele in endList) { frontNumContainer[ele.times] = ele.front; } float x1, x2; float a, b, c; a = frontNumContainer[2]; b = frontNumContainer[1]; c = frontNumContainer[0]; float Diat = (float)Math.Sqrt(b * b - 4 * a * c); x1 = ((-b) + Diat) / (2 * a); x2 = ((-b) - Diat) / (2 * a); if (a < 0) { string op3 = IChar; IChar = oppChar; oppChar = op3; a = -a; b = -b; c = -c; } if (x1 > x2) { float x = x1; x1 = x2; x2 = x; } #endregion if ((b * b - 4 * a * c) < 0) { return("x∈∅"); } else if ((b * b - 4 * a * c) == 0) { if (IChar == ">" || IChar == ">=") { return("x≠" + (-(b) / 2 * a).ToString()); } else { return("x∈∅"); } } else { string BOp; string SOp; string Lk; string Rk; if (haveEq) { BOp = ">="; SOp = "<="; Lk = "["; Rk = "]"; } else { BOp = ">"; SOp = "<"; Lk = "("; Rk = ")"; } if (IChar == ">" || IChar == ">=") { return(string.Format("{{x {0} {1} or x {2} {3}}}", SOp, x1.ToString(), BOp, x2.ToString())); } if (IChar == "<" || IChar == "<=") { return(string.Format("x∈{0} {1},{2} {3}", Lk, x1.ToString(), x2.ToString(), Rk)); } } } else { showInformation("抱歉", "由于能力问题。我们只设计了二次不等式和一次不等式."); } return(""); }