Exemplo n.º 1
0
        public static Ration_numb operator -(Ration_numb A, int i_B)
        {
            Ration_numb B = new Ration_numb(i_B, 1);

            if (A.denum == B.denum)
            {
                return(new Ration_numb(A.num - B.num, A.denum));
            }
            return(new Ration_numb(A.num - B.num * A.denum, A.denum));
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            try
            {
                Ration_numb rn1 = new Ration_numb();
                Console.WriteLine(rn1);

                rn1[0] = 2;
                rn1[1] = 3;
                Console.WriteLine(rn1);

                Ration_numb rn2 = new Ration_numb(1, 2);
                Console.WriteLine(rn2);

                //Операции между рациональными числами
                Console.WriteLine(rn1 + rn2);
                Console.WriteLine(rn1 - rn2);
                Console.WriteLine(rn1 * rn2);
                Console.WriteLine(rn1 / rn2);

                //Инкремент для рационального числа
                Console.WriteLine(++rn1);

                //Декремент для рационального числа
                //Console.WriteLine(--rn1);

                //Операции между рациональным и целым числом
                Console.WriteLine(rn1 + 3);
                Console.WriteLine(rn1 - 3);
                Console.WriteLine(rn1 * 3);
                Console.WriteLine(rn1 / 3);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nОшибка брошена из класса: " + ex.TargetSite.DeclaringType.Name + ", при использовании метода: " + ex.TargetSite + ", строка " + new System.Diagnostics.StackTrace(ex, true).GetFrame(0).GetFileLineNumber());
                Console.WriteLine("Ошибка вызвана в методе: " + new System.Diagnostics.StackTrace(ex, true).GetFrame(1).GetMethod() + ", строка " + new System.Diagnostics.StackTrace(ex, true).GetFrame(1).GetFileLineNumber());
            }
            Console.ReadKey();
        }
Exemplo n.º 3
0
        public static Ration_numb operator /(Ration_numb A, int i_B)
        {
            Ration_numb B = new Ration_numb(i_B, 1);

            return(new Ration_numb(A.num, A.denum * B.num));
        }