控制檯應用程序下的計算器(調用子類)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            double a = 0;
            double b = 0;
            double c = 0;
            Console.WriteLine("請輸入第一個數:");
            a = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("請輸入第二個數:");
            b = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("請輸入運算符號!");
            string hao = Console.ReadLine();
            leiku.fulei fl = gethao(hao);
            fl.a = a;
            fl.b = b;
            c = fl.GetC();
            Console.WriteLine(c);
            Console.ReadKey();
        }
        private static leiku.fulei gethao(string hao)
        {
            leiku.fulei fl = null;
            switch (hao)
            {
                case "+":
                    fl = new leiku.add();
                    break;
                case "-":
                    fl = new leiku.jian();
                    break;
                case "*":
                    fl = new leiku.cheng();
                    break;
                case "/":
                    fl = new leiku.chu();
                    break;
                case "sqrt":
                    fl = new leiku.sqrt();
                    break;
                case "sin":
                    fl = new leiku.sin();
                    break;
            }
            return fl;
        }
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章