public static string DoOperation(string s) // Возвращает ответ в виде строки { try { string[] operands = GetOperands(s); string operation = GetOperation(s)[0]; string answer = ""; if (operation == "reverse" || operation == "Sqrt" || operation == "division" || operation == "expX" || operation == "sin" || operation == "Cos" || operation == "tg" || operation == "Sqr" || operation == "factor") { answer = SingleOperation[operation](double.Parse(operands[0])).ToString(); } else if (operation == "π" || operation == "e") { answer = Print(s); } else { answer = DoubleOperation[operation](double.Parse(operands[0]), double.Parse(operands[1])).ToString(); } return(answer); } catch { string answer = "Ошибка"; return(answer); } }
public static string DoOperation(string s) { try { string[] operands = GetOperands(s); //получить операнды string operation = GetOperation(s)[0]; //получить операцию string res = ""; if (operation == "=") //если число отрицательное, минус относится к числу, а не к операции { operation = operation.Remove(operation.Length - 1); operation += "+"; //при вычитании прибавляется отрицательное число } if (operation == "+" || operation == "-" || operation == "*" || operation == "/" || operation == "mod" || operation == "div" || operation == "^") { res = DoubleOperation[operation](double.Parse(operands[0]), double.Parse(operands[1])).ToString(); } else { res = SingleOperation[operation](double.Parse(operands[0])).ToString(); } return(res); //вычислить и получить строку } catch { return("Ошибка"); } }
public static string DoOperation(string s) { string[] operands = GetOperands(s); //получить операнды string op = GetOperation(s); //получить операцию s = DoubleOperation[op](double.Parse(operands[0]), double.Parse(operands[1])).ToString(); return(s); //вычислить и получить строку; }
public static string DoOperation(string s) { string[] operands; string operation; operands = GetOperands(s); operation = GetOperation(s); s = DoubleOperation[operation](double.Parse(operands[0]), double.Parse(operands[1])).ToString(); return(s); }
private static IOperationProcessor GetProcessor() { var plusOneOperation = new PlusOneOperation(); var plusTwoOperation = new PlusTwoOperation { LeftSuccesor = plusOneOperation }; var doubleOperation = new DoubleOperation { RightSuccesor = plusOneOperation, LeftSuccesor = plusTwoOperation }; return(doubleOperation); }
static void Main() { try { // TODO: Create an object of type DoubleOperation providing // MultipleByTwo as the method to call. DoubleOperation d = new DoubleOperation(MultiplyByTwo); Console.WriteLine("{0}\n", d(4)); //Console.WriteLine("{0}\n", MultiplyByTwo(4)) // TODO: Create an object of type DoubleOperation providing // DivideByFive as the method to call. d = new DoubleOperation(DivideByFive); Console.WriteLine("{0}\n", d(75)); //Console.WriteLine("{0}\n", DivideByFive(75)); // TODO: Create an object of type DoubleOperation providing // SquareNumber as the method to call. d = new DoubleOperation(SquareNumber); Console.WriteLine("{0}\n", d(100)); //Console.WriteLine("{0}\n", SquareNumber(100)); // TODO: Create an object of type DoubleOperation providing // Divide100ByValue as the method to call. d = new DoubleOperation(Divide100ByValue); Console.WriteLine("{0}\n", d(0)); //Console.WriteLine("{0}\n", Divide100ByValue(0)); } catch (Exception e) { Console.WriteLine(e.Message); } Console.Write("\nPress <ENTER> to end: "); Console.ReadLine(); }
private void Run(Action <DoubleOperation> action, DoubleOperation operation) { action.Invoke(operation); RefreashStats(); }
public MyDouble(double obj) { DoubleValue = obj; Calculator = DoubleOperation.GetInstance(); }