public void processTask1()
        {
            Input input    = new Input();
            IFrac computer = new FracComputer();

            Console.WriteLine("Print some data to run this task(2 fracs and single natural val):");
            Structures.Frac frac1 = input.inputFrac();
            Structures.Frac frac2 = input.inputFrac();
            int             n     = input.inputNaturalInt();

            Console.WriteLine("First frac double value is {0}", Math.Round(computer.doubleVal(frac1), 3));
            Console.WriteLine("Second frac double value is {0}", Math.Round(computer.doubleVal(frac2), 3));
            Console.WriteLine(frac1 + " + " + frac2 + " = " + computer.ToStringWithIntegerPart(computer.plus(frac1, frac2)));
            Console.WriteLine(frac1 + " - " + frac2 + " = " + computer.ToStringWithIntegerPart(computer.minus(frac1, frac2)));
            Console.WriteLine(frac1 + " * " + frac2 + " = " + computer.ToStringWithIntegerPart(computer.multiply(frac1, frac2)));
            try
            {
                Console.WriteLine(frac1 + " / " + frac2 + " = " + computer.ToStringWithIntegerPart(computer.divide(frac1, frac2)));
            }
            catch (ArithmeticException e)
            {
                MessageBox.Show(e.ToString());
            }
            Console.WriteLine($"First sum({n}) = n/(n + 1) = " + computer.caclSum1(n));
            try
            {
                Console.WriteLine($"Second sum({n}) = (n + 1)/(2*n) = " + computer.caclSum2(n));
            }
            catch (ArgumentException e)
            {
                MessageBox.Show(e.ToString());
            }
            Console.WriteLine(new string('-', 35));
        }
Exemple #2
0
        public Frac(long nom, long denom)
        {
            FracComputer fracComp = new FracComputer();
            long         divisor  = fracComp.findGreatestCommonDivisor(Math.Abs(nom), Math.Abs(denom));

            this.nom   = nom / divisor;
            this.denom = denom / divisor;
        }