計算器代碼1

using System;spa

using System.Collections.Generic;get

using System.Linq;it

using System.Text;io


namespace Caculatorclass

{im

    class caculatorstatic

    {cas

        public static double x, y, ans;return

        public static char cal;void

        public caculator() { }

        public static void calc(double x, double y, char cal)

        {

            switch (cal)

            {

                case '+': ans = x + y; break;

                case '-': ans = x - y; break;

                case '*': ans = x * y; break;

                case '/': ans = x / y; break;

                case '%': ans = x % y; break;

                case 's': ans = Math.Sqrt(x); break;

                default: break;

            }

            


        }

        public static void calc(double x, char cal)

        {

            switch (cal)

            {

                case 'x': ans = Math.Pow(x, 2); break;

                case 's': ans = Math.Sqrt(x); break;

                default: break;

            }

        }

        public static double getans()

        {

            return ans;

        }

    }

}


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;


namespace Caculator

{

    class simplecal

    {

        public double ans(double x, double y, char cal)

        {

            caculator.calc(x, y, cal);

            return caculator.getans();

        }

        public double ans(double x, char cal)

        {

            caculator.calc(x, cal);

            return caculator.getans();

        }

    }

}

相關文章
相關標籤/搜索