Ejemplo n.º 1
0
 public bool TestAdd()
 {
     Fraction test1 = new Fraction(15, 20);
     Fraction test2 = new Fraction(5, 20);
     Fraction test3 = new Fraction(1, 1);
     test1 = test1.Add(test2);
     if (test1.Equals(test3))
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Ejemplo n.º 2
0
        public bool TestAdd()
        {
            Fraction test1 = new Fraction(15, 20);
            Fraction test2 = new Fraction(5, 20);
            Fraction test3 = new Fraction(1, 1);

            test1 = test1.Add(test2);
            if (test1.Equals(test3))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Evaluates operands according to the given operator.
        /// </summary>
        /// <param name="ops">operator</param>
        /// <param name="b">operand</param>
        /// <param name="a">operand</param>
        /// <returns></returns>
        public Fraction ApplyOp(string ops, Fraction b, Fraction a)
        {
            switch (ops)
            {
            case "*":
                return(a.Multiply(b));

            case "+":
                return(a.Add(b));

            case "-":
                return(a.Subtract(b));

            case "/":
                return(a.Divide(b));

            default: throw new ArgumentException($"Invalid operator.Operator: {ops}");
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Fraction f1 = new Fraction(25, 7);
            Fraction f2 = new Fraction(19, 14);
            Fraction f3 = f1.Add(f2);

            Console.WriteLine(f3);

            try
            {
                Fraction f4 = new Fraction(10, 0); //this throws an exception
                Console.WriteLine(f4);             // skips
            }
            catch (Exception ex)                   // this catch it
            {
                Console.WriteLine(ex);
            }
            Console.WriteLine("Finished");
            f3 = f1 + f2;
            Console.WriteLine(f1 * f2);
            Console.WriteLine(f1 / f2);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            Fraction f1 = new Fraction(25, 7);
            Fraction f2 = new Fraction(19, 14);
            Fraction f3 = f1.Add(f2);

            Console.WriteLine(f3);
            try
            {
                Fraction f4 = new Fraction(10, 0);
                Console.WriteLine(f4);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            Console.WriteLine("Finished.");
            f3 = f1 + f2;
            Console.WriteLine(f1 * f2);
            Console.WriteLine(f1 / f2);
            Console.WriteLine(f1 - f2);
            double result = (f1 - f2) / f3;
        }