//计算一个算式不输出出错信息 public static bool Number_Compute2(String si, out Double out1) { out1 = 0; if (si.Length == 0) return false; Formula f1; try { f1 = new Formula(si, 0); } catch (Exception) { Error = "内存空间不足"; return false; } if (!f1.Check_Bracket()) return false; f1.Formula_Adjust(); if (!f1.Number_Compute(out out1)) return false; return true; }
//带括号检查、括号替换和出错信息输出功能的多项式综合运算 public static bool Multinomial_Compute(String si, out String out1) { out1 = ""; if (si.Length == 0) { MessageBox.Show("请输入一个算式", "无法计算", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return false; } Formula f; try { f = new Formula(si, 0); } catch (Exception) { Error = "内存空间不足"; return false; } if (!f.Check_Bracket()) { MessageBox.Show("多项式非法:\n\n" + Error, "无法计算", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return false; } f.Formula_Adjust(); Double d; if (f.Number_Compute(out d)) { out1 = Formula.Number_Adjust(d); return true; } MultinomialC c; try { c = new MultinomialC(f.formula); } catch (Exception) { Error = "内存空间不足"; return false; } Error = null; if (!c.Multinomial_Compute(out c)) { if (Error == null) MessageBox.Show("多项式非法", "无法计算", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); else MessageBox.Show("多项式非法:\n\n" + Error, "无法计算", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return false; } out1 = c.ToString(); return true; }
//计算一个用字符串表示的算式并用消息框给出出错信息 public static bool Number_Compute(String si, int angle_manner, out Double out1) { out1 = 0; if (si.Length == 0) { MessageBox.Show("请输入一个算式", "无法计算", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return false; } Formula f1; try { f1 = new Formula(si, angle_manner); } catch (Exception) { Error = "内存空间不足"; return false; } if (!f1.Check_Bracket()) { MessageBox.Show("算式非法:\n\n" + Error, "无法计算", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return false; } f1.Formula_Adjust(); Error = null; if (!f1.Number_Compute(out out1)) { if (Error == null) MessageBox.Show("算式非法", "无法计算", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); else MessageBox.Show("算式非法:\n\n" + Error, "无法计算", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return false; } return true; }