/// <summary>
        /// 此函数完成计算器的简单计算
        /// </summary>
        /// <param name="args">输入参数</param>
        static void Main(string[] args)
        {
            /*
             * GetResult();        //利用简单的函数完成计算器功能
             *
             * //下面是利用类的封装完成计算机功能
             * //利用简单的封装完成了业务的封装,使得程序之间的耦合性大大降低,可维护性大大增强,程序变得可复用和可扩展
             * Console.Write("Please input the num A:");
             * string a = Console.ReadLine();
             * Console.Write("Please input the operator:");
             * string operatorStr=Console.ReadLine();
             * Console.Write("Please input the num B:");
             * string b = Console.ReadLine();
             * double result = Operation.GetResult(Convert.ToDouble(a), Convert.ToDouble(b), operatorStr);
             * Console.Write(result.ToString());
             * Console.ReadKey();
             * */
            Console.Write("Please input the num A:");
            string a = Console.ReadLine();

            Console.Write("Please input the operator:");
            string operatorStr = Console.ReadLine();

            Console.Write("Please input the num B:");
            string    b    = Console.ReadLine();
            Operation oper = OperationFactory.CreateOperation(operatorStr);

            oper.NumberA = Convert.ToDouble(a);
            oper.NumberB = Convert.ToDouble(b);
            double result = oper.GetResult();

            Console.Write(result.ToString());
            Console.ReadKey();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Operation op = OperationFactory.CreateOperation("+");

            op.NumberA = 10;
            op.NumberB = 20;
            Console.WriteLine(op.GetResult());
        }
        static void Main(string[] args)
        {
            Operation o = OperationFactory.CreateOperation("+");

            o.NumberA = 5;

            o.NumberB = 4;

            Console.WriteLine(o.Method());

            Console.Read();
        }
Exemple #4
0
        static void Main(string[] args)
        {
            string    oper      = string.Empty;
            Operation operation = new Operation();

            Console.Title = "简单工厂模式";
            Console.WriteLine("加减乘除:+-*/");
            Console.WriteLine("请输入运算法则:");
            oper      = Console.ReadKey().KeyChar.ToString();
            operation = OperationFactory.CreateOperation(oper);
            Console.WriteLine("\n请输入第一个数字:");
            operation.NumberA = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("请输入第二个数字:");
            operation.NumberB = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("最后的结果是" + operation.GetResult() + "按任意键结束");
            Console.ReadKey();
        }
Exemple #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("请输入数字A:");
            string numberA = Console.ReadLine();

            Console.WriteLine("请输入运算符(+,-,*,/):");
            string operater = Console.ReadLine();

            Console.WriteLine("请输入数字B:");
            string    numberB   = Console.ReadLine();
            Operation operation = null;

            operation         = OperationFactory.CreateOperation(operater);
            operation.NumberA = Convert.ToDouble(numberA);
            operation.NumberB = Convert.ToDouble(numberB);
            Console.WriteLine("计算结果为:" + operation.GetResult());
            Console.ReadKey();
        }
Exemple #6
0
        static void Main(string[] args)
        {
            Console.WriteLine("请输入第一个数:");
            double dNum1 = Convert.ToDouble(Console.ReadLine());

            Console.WriteLine("请输入第二个数:");
            double dNum2 = Convert.ToDouble(Console.ReadLine());

            Console.WriteLine("请输入操作符:");
            string strOp = Console.ReadLine();

            Operation op = OperationFactory.CreateOperation(strOp);

            if (op == null)
            {
                Console.WriteLine("没有对应的操作符.");
                return;
            }
            Console.WriteLine("{0}{1}{2}={3}", dNum1, strOp, dNum2, op.GetResult(dNum1, dNum2));
        }
 static void Main(string[] args)
 {
     try
     {
         Console.WriteLine("请输入第一个运算数字A:");
         string a = Console.ReadLine();
         Console.WriteLine("请输入第二个运算数字B:");
         string b = Console.ReadLine();
         Console.WriteLine("请输入运算符号(+,-,*,/):");
         string    strOperation = Console.ReadLine();
         string    strResult    = "";
         Operation operation    = OperationFactory.CreateOperation(strOperation);
         strResult = operation.GetResult(Convert.ToDouble(a), Convert.ToDouble(b)).ToString();
         Console.WriteLine("运算结果是:{0}", strResult);
         Console.ReadLine();
     }
     catch (Exception ex)
     {
         Console.WriteLine("你输入的有错:" + ex.Message);
     }
 }
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("請輸入數字A");
                string strNumA = Console.ReadLine();
                Console.WriteLine("請輸入數字運算符號(+、-、*、/):");
                string strOperate = Console.ReadLine();
                Console.WriteLine("請輸入數字B");
                string strNumB = Console.ReadLine();

                var oper = OperationFactory.CreateOperation(strOperate);
                oper.numA = Convert.ToDouble(strNumA);
                oper.numB = Convert.ToDouble(strNumB);
                Console.WriteLine("結果是:" + oper.GetResult());
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("輸入有錯:" + ex.Message);
            }
        }