Exemple #1
0
        static void Main(string[] args)
        {
            MixedNumber test1 = new MixedNumber(1, -151, -10);

            Console.WriteLine(test1);
            MixedNumber test3 = new MixedNumber(1.32);
            MixedNumber test4 = new MixedNumber(16, 5);

            Console.WriteLine("Dodawanie: " + test3 + " oraz " + test4 + " = " + (test3 + test4));

            MixedNumber test5 = new MixedNumber(2, 1, 2);
            MixedNumber test6 = new MixedNumber(-1, 1, 4);

            Console.WriteLine("Dodawanie: " + test5 + " oraz " + test6 + " = " + (test5 + test6));

            MixedNumber test7 = new MixedNumber(-2, 1, 2);
            MixedNumber test8 = new MixedNumber(1, 1, 4);

            Console.WriteLine("Dodawanie: " + test7 + " oraz " + test8 + " = " + (test7 + test8));

            MixedNumber test9  = new MixedNumber(-1, 1, 2);
            MixedNumber test10 = new MixedNumber(1, 1, 2);

            Console.WriteLine("Dodawanie: " + test9 + " oraz " + test10 + " = " + (test9 + test10));

            Console.WriteLine("Licznik zmian dla 2 dodawanej liczby: " + test10.licznikZmian);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            PrintInfo();

            MixedNumber test0 = new MixedNumber();

            WriteLine(test0);

            MixedNumber test1 = new MixedNumber(2, -141, -10);

            WriteLine(test1);

            MixedNumber test3 = new MixedNumber(3.39);
            MixedNumber test4 = new MixedNumber(2, 12, 16);

            WriteLine($"Adding: {test3}  +  {test4} =  {test3 + test4}");

            MixedNumber test5 = new MixedNumber(3, 1, 2);
            MixedNumber test6 = new MixedNumber(-1, 2, 4);

            WriteLine($"Adding: {test5}  +  {test6} =  {test5 + test6}");

            MixedNumber test7 = new MixedNumber(-2, 3, 9);
            MixedNumber test8 = new MixedNumber(1, 6, 4);

            WriteLine($"Adding: {test7}  +  {test8} =  {test7 + test8}");

            MixedNumber test9  = new MixedNumber(-1, 1, 2);
            MixedNumber test10 = new MixedNumber(1, 1, 2);

            WriteLine($"Adding: {test9}  +  {test10} =  {test9 + test10}");

            WriteLine("Shift couneter: " + MixedNumber.ShiftCounter);
        }
Exemple #3
0
        static void mixedNumberTest()
        {
            var array = new ListOfArrayList <MixedNumber>(3);

            MixedNumber myNumber = new MixedNumber(5.25);

            array.Add(myNumber);
            array.Add(new MixedNumber(43, 23));
            array.Add(new MixedNumber(10.25));
            array.Add(new MixedNumber(81, 2));

            WriteLine("Aktualna tablica: ");
            WriteLine(array);

            WriteLine("Metoda RemoveAt(2)");
            array.RemoveAt(2);

            WriteLine("Aktualna tablica: ");
            WriteLine(array);

            WriteLine("Metoda IndexOf(myNumber)");
            WriteLine(array.IndexOf(myNumber));

            WriteLine("Metoda Contains(myNumber)");
            WriteLine(array.Contains(myNumber));

            WriteLine("Metoda Trim()");
            array.Trim();

            WriteLine("Aktualna tablica: ");
            WriteLine(array);

            WriteLine("Metoda Remove(myNumber)");
            array.Remove(myNumber);

            WriteLine("Aktualna tablica: ");
            WriteLine(array);

            WriteLine("Count");
            WriteLine(array.Count);

            WriteLine("Metoda Clear()");
            array.Clear();

            WriteLine("Aktualna tablica: ");
            WriteLine(array);
        }
        public static MixedNumber operator +(MixedNumber fst, MixedNumber scd)
        {
            int firstDenominator = fst.denominatorNumber;
            int secondDenominator = scd.denominatorNumber;
            int firstNumarator, secondNumerator, sumNumerator, commonDenominator;

            //numerator of the (first) improper fraction
            if (fst.IntegerPart < 0)
            {
                firstNumarator = -1 * fst.Numerator + fst.IntegerPart * fst.Denominator;
            }
            else
            {
                firstNumarator = fst.Numerator + fst.IntegerPart * fst.Denominator;
            }
            //numerator of the (second) improper fraction
            if (scd.IntegerPart < 0)
            {
                secondNumerator = -1 * scd.Numerator + scd.IntegerPart * scd.Denominator;
            }
            else
            {
                secondNumerator = scd.Numerator + scd.IntegerPart * scd.Denominator;
            }
            //common denominator
            if (fst.Denominator == scd.Denominator)
            {
                commonDenominator = scd.Denominator;
                sumNumerator      = firstNumarator + secondNumerator;
            }
            else
            {
                commonDenominator = fst.Denominator * scd.Denominator;
                sumNumerator      = firstNumarator * secondDenominator + secondNumerator * firstDenominator;
            }

            MixedNumber sum = new MixedNumber();

            sum.Numerator   = sumNumerator;
            sum.Denominator = commonDenominator;
            if (sumNumerator < 0)
            {
                sum.IntegerPart = -1 * sum.IntegerPart;
            }
            return(sum);
        }
Exemple #5
0
 public static MixedNumber dodawanie(MixedNumber zestaw1, MixedNumber zestaw2)
 {
     if (zestaw1.calkowita == 0 && zestaw2.calkowita == 0)
     {
         return(new MixedNumber((zestaw1.licznik * zestaw2.mianownik) + (zestaw2.licznik * zestaw1.mianownik), zestaw1.mianownik * zestaw2.mianownik));
     }
     else if (zestaw1.calkowita < 0 && zestaw2.calkowita >= 0)
     {
         return(new MixedNumber(Math.Round(zestaw1.calkowita + zestaw2.calkowita - Math.Round((double)zestaw1.licznik / zestaw1.mianownik, 5) + Math.Round((double)zestaw2.licznik / zestaw2.mianownik, 5), 5)));
     }
     else if (zestaw1.calkowita >= 0 && zestaw2.calkowita < 0)
     {
         return(new MixedNumber(Math.Round(zestaw1.calkowita + zestaw2.calkowita + Math.Round((double)zestaw1.licznik / zestaw1.mianownik, 5) - Math.Round((double)zestaw2.licznik / zestaw2.mianownik, 5), 5)));
     }
     else
     {
         return(new MixedNumber(zestaw1.calkowita + zestaw2.calkowita, (zestaw1.licznik * zestaw2.mianownik) + (zestaw2.licznik * zestaw1.mianownik), zestaw1.mianownik * zestaw2.mianownik));
     }
 }