Пример #1
0
        public static SoNguyenLon operator ^(SoNguyenLon x, SoNguyenLon y)
        {
            SoNguyenLon result = new SoNguyenLon();

            result.Number = LuyThua(x.Number, y.Number);
            return(result);
        }
Пример #2
0
        public static SoNguyenLon operator *(SoNguyenLon x, SoNguyenLon y)
        {
            SoNguyenLon result = new SoNguyenLon();

            result.Number = Nhan(x.Number, y.Number);
            return(result);
        }
Пример #3
0
        public static SoNguyenLon operator %(SoNguyenLon x, SoNguyenLon y)
        {
            SoNguyenLon result = new SoNguyenLon();

            result.Number = ChiaLayDu(x.Number, y.Number);
            return(result);
        }
Пример #4
0
        public static void ChuanHoa(ref SoNguyenLon x, ref SoNguyenLon y)
        {
            string xx = x.ToString();
            string yy = y.ToString();

            XoaSoKhong(ref xx);
            XoaSoKhong(ref yy);
            ThemDauCach(ref xx, ref yy);
            x = xx;
            y = yy;
        }
Пример #5
0
        public static SoNguyenLon Calc(List <string> input)
        {
            List <string> stack = new List <string>();

            for (int i = 0; i < input.Count; i++)
            {
                if (IsOperator(input[i]) == 0)
                {
                    stack.Add(input[i]);
                }
                else
                {
                    SoNguyenLon b = Pop(ref stack);
                    SoNguyenLon a = Pop(ref stack);
                    SoNguyenLon c = "";
                    if (input[i] == "+")
                    {
                        c = a + b;
                    }
                    else if (input[i] == "-")
                    {
                        c = a - b;
                    }
                    else if (input[i] == "*" || input[i] == "x")
                    {
                        c = a * b;
                    }
                    else if (input[i] == "/" || input[i] == ":")
                    {
                        c = a / b;
                    }
                    else if (input[i] == "^")
                    {
                        c = a ^ b;
                    }
                    else if (input[i] == "%")
                    {
                        c = a % b;
                    }
                    else if (input[i] == "!")
                    {
                        stack.Add(a.ToString());
                        c = SoNguyenLon.GiaiThua(b.ToInt());
                    }
                    stack.Add(c.ToString());
                }
            }
            return(Pop(ref stack));
        }