public TFract Reduce() { int a, b, ta, tb, tmp, gcd; a = ta = this.Num; b = tb = this.Den; if (a < 0) { ta = Math.Abs(ta); } while (ta != 0) { if (ta < tb) { tmp = ta; ta = tb; tb = tmp; } ta = ta - tb; } gcd = tb; a = a / gcd; b = b / gcd; this.Num = a; this.Den = b; TFract F = new TFract(a, b); return(F); }
public void ResultShowEqual(TFract A, TFract B, bool C, TextBox tR, ComboBox cO) { tR.Text += A.ToString() + " " + cO.Text + " " + B.ToString() + " is " + C.ToString() + '\r' + '\n' + '\r' + '\n'; }
public static TFract operator +(int n, TFract a) { TFract b = new TFract(); TFract c = new TFract(); b.SetNum(n); b.SetDen(1); c = b + a; return(c); }
public static TFract operator +(TFract a, int n) { TFract b = new TFract(); TFract c = new TFract(); b.SetNum(n); b.SetDen(1); c = a + b; return(c); }
public void ResultShowCalc(TFract A, TFract B, TFract C, TextBox tR, ComboBox cO) { tR.Text += A.ToString() + " " + cO.Text + " " + B.ToString() + " = " + C.ToString() + " = " + C.Reduce().ToString() + " = " + C.ToFloat().ToString() + '\r' + '\n' + '\r' + '\n'; }
public override bool Equals(object obj) { if (obj.GetType() != GetType()) { return(false); } TFract t = (TFract)obj; return(Num == t.Num && Den == t.Den); }
private void buttonResult_Click(object sender, EventArgs e) { try { TFract A = new TFract(Int32.Parse(tBf1_num.Text), Int32.Parse(tBf1_den.Text)); TFract B = new TFract(Int32.Parse(tBf2_num.Text), Int32.Parse(tBf2_den.Text)); TFract C; if(comboBoxOperation.Text == "+") { C = A + B; ResultShowCalc(A, B, C, textBoxResult, comboBoxOperation); } else if (comboBoxOperation.Text == "-") { C = A - B; ResultShowCalc(A, B, C, textBoxResult, comboBoxOperation); } else if (comboBoxOperation.Text == "*") { C = A * B; ResultShowCalc(A, B, C, textBoxResult, comboBoxOperation); } else if (comboBoxOperation.Text == "/") { C = A / B; ResultShowCalc(A, B, C, textBoxResult, comboBoxOperation); } else if (comboBoxOperation.Text == "<") { bool r; r = A < B; ResultShowEqual(A, B, r, textBoxResult, comboBoxOperation); } else if (comboBoxOperation.Text == ">") { bool r; r = A > B; ResultShowEqual(A, B, r, textBoxResult, comboBoxOperation); } else if (comboBoxOperation.Text == "<=") { bool r; r = A <= B; ResultShowEqual(A, B, r, textBoxResult, comboBoxOperation); } else if (comboBoxOperation.Text == ">=") { bool r; r = A >= B; ResultShowEqual(A, B, r, textBoxResult, comboBoxOperation); } else if (comboBoxOperation.Text == "=") { bool r; r = (A == B); ResultShowEqual(A, B, r, textBoxResult, comboBoxOperation); } } catch(Exception ex) { textBoxResult.Text += ex.Message + '\r' + '\n' + '\r' + '\n'; } }
private void buttonResult_Click(object sender, EventArgs e) { /*TFract f1 = new TFract(2, 5); * TFract f2 = new TFract(3, 6); * TFract f3; * f3 = (f1 + f2).Reduce(); * * textBoxResult.Text = f3.ToString();*/ /*TFract f1 = new TFract(3, 5); * TFract f2 = new TFract(3, 2); * * if (f1 > f2) { textBoxResult.Text = f1.ToString() + " is bigger"; }; * if (f1 < f2) { textBoxResult.Text = f2.ToString() + " is bigger"; };*/ /*try * { * TFract f2 = new TFract(3, 0); * } * catch(TFractException ex) * { * textBoxResult.Text = ex.Message; * }*/ /*TFract f1 = new TFract(1, 2); * TFract f2 = new TFract(2, 3); * TFract f3 = new TFract(3, 4); * TFract f4 = new TFract(4, 5); * TFract f5 = f1 - f2 - f3 - f4; * * textBoxResult.Text = f5.Reduce().ToFloat().ToString();*/ try { TFract A = new TFract(Int32.Parse(tBf1_num.Text), Int32.Parse(tBf1_den.Text)); TFract B = new TFract(Int32.Parse(tBf2_num.Text), Int32.Parse(tBf2_den.Text)); TFract C; if (comboBoxOperation.Text == "+") { C = A + B; ResultShowCalc(A, B, C, textBoxResult, comboBoxOperation); } else if (comboBoxOperation.Text == "-") { C = A - B; ResultShowCalc(A, B, C, textBoxResult, comboBoxOperation); } else if (comboBoxOperation.Text == "*") { C = A * B; ResultShowCalc(A, B, C, textBoxResult, comboBoxOperation); } else if (comboBoxOperation.Text == "/") { C = A / B; ResultShowCalc(A, B, C, textBoxResult, comboBoxOperation); } else if (comboBoxOperation.Text == "<") { bool r; r = A < B; ResultShowEqual(A, B, r, textBoxResult, comboBoxOperation); } else if (comboBoxOperation.Text == ">") { bool r; r = A > B; ResultShowEqual(A, B, r, textBoxResult, comboBoxOperation); } else if (comboBoxOperation.Text == "<=") { bool r; r = A <= B; ResultShowEqual(A, B, r, textBoxResult, comboBoxOperation); } else if (comboBoxOperation.Text == ">=") { bool r; r = A >= B; ResultShowEqual(A, B, r, textBoxResult, comboBoxOperation); } else if (comboBoxOperation.Text == "=") { bool r; r = (A == B); ResultShowEqual(A, B, r, textBoxResult, comboBoxOperation); } } catch (Exception ex) { textBoxResult.Text += ex.Message + '\r' + '\n' + '\r' + '\n'; } }