static void Main(string[] args) { try { IMathObject f = new Fraction(-8, 5); Console.WriteLine(f); IMathObject g = new Fraction(-2, 5); Console.WriteLine(g); IMathObject k = f.Summa(g); IMathObject z = g.Multiply(2.0); Console.WriteLine(z); Console.WriteLine(k); IMathObject f1 = new Fraction(15, -5); Console.WriteLine(f1); IMathObject p = IMathObjectMethods.GetSummaInList(f, g, k, z, f1); Console.WriteLine(p); IMathObject[] list = { f, g, k, z, f1 }; IMathObject p1 = IMathObjectMethods.GetSummaInList(list); Console.WriteLine(p1); Console.ReadLine(); } catch (Exception e) { Console.WriteLine(e.Message); Console.ReadLine(); } }
public IMathObject Multiply(IMathObject ob) { Fraction obj1 = ob as Fraction; int N = Numerator * obj1.Numerator; int D = obj1.Denominator * Denominator; Fraction result = new Fraction(N, D); return(result); }
public IMathObject Substract(IMathObject ob) { Fraction obj1 = ob as Fraction; int N = obj1.Denominator * Numerator - obj1.Numerator * Denominator; int D = obj1.Denominator * Denominator; Fraction result = new Fraction(N, D); return(result); }
public static IMathObject GetSummaInList(params IMathObject[] list) { IMathObject result = list[0]; for (int i = 1; i < list.Length; i++) { result = result.Summa(list[i]); } return(result); }
/// Safe to call, even if one or both are null. Returns true if both are null. public static bool NullCheckingEquals(this IMathObject obj1, IMathObject obj2) => obj1 == null ? obj2 == null ? true : false : obj2 == null ? false : obj1.Equals(obj2);