harshityadav95
1/24/2018 - 12:05 PM

code.cs

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

namespace calculatorApp
{
    class operations
    {
        double _retrunValue = 0;
    
       /// <summary>
       /// Main calculation engine which apply operation based on operand and operator passed
       /// </summary>
       /// <param name="x"></param>
       /// <param name="v1"></param>
       /// <param name="v2"></param>
       /// <returns></returns>
        public double engine(string x, double v1,double v2=0)
        {
            switch (x)
            {
                case "+":
                    {
                       _retrunValue = v1 + v2;
                    }
                    break;

                case "-":
                    {
                       _retrunValue = v1 - v2;

                    }
                    break;
                case "/":
                    {
                        
                       
                            if (v2==0)
                            {
                                throw new System.DivideByZeroException();
                            }
                           _retrunValue = v1 / v2; 
                       
                       
                    }
                    break;

                case "√":
                    {
                       _retrunValue = Math.Sqrt(v1);

                    }
                    break;
                case "*":
                    {
                       _retrunValue = v1*v2;

                    }
                    break;

                case "±":
                    {
                       _retrunValue = v1 * -1;

                    }
                  break;
                case "%":
                  {
                      if (v2 == 0 || v2==0)
                      {
                          throw new System.DivideByZeroException();
                      }
                      
                      _retrunValue = v1 % v2;
                      
                     

                  }
                  break;
                case "1/x":
                  {
                      if (v1==0)
                      {
                          throw new System.DivideByZeroException();
                      }
                         _retrunValue = 1/v1;
                      
                    

                  }
                  break;
            }
            return _retrunValue;
        }
          
  


    }
}