Created
January 24, 2018 12:05
-
-
Save harshityadav95/ad005eb5b0e2a3bc9f30d0596face211 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment