public Facade() { _one = new Add(); _two = new Subtract(); _three = new Multiple(); _four = new Divide(); }
static void Main(string[] args) { double firstNumber; double secondNumber; double a; double b; double result1; double result2; double result3; double result4; double result5; Console.WriteLine("First Number"); firstNumber = double.Parse(Console.ReadLine()); Console.WriteLine("Second Number"); secondNumber = double.Parse(Console.ReadLine()); Add add = new Add(); Subtract subtract = new Subtract(); Multiply multiply = new Multiply(); Divide divide = new Divide(); Percentage percentage = new Percentage(); result1 = add.Addition(firstNumber, secondNumber); Console.WriteLine("Addition: " + result1); result2 = subtract.Subtraction(firstNumber, secondNumber); Console.WriteLine("Subtraction: " + result2); result3 = multiply.Multiplication(firstNumber, secondNumber); Console.WriteLine("Multiplication: " + result3); result4 = divide.Division(firstNumber, secondNumber); Console.WriteLine("Division: " + result4); Console.WriteLine("Press 1 to calculate Percentage or any other number to exit the program"); double x = double.Parse(Console.ReadLine()); if (x == 1) { Console.WriteLine("Enter the x: "); a = double.Parse(Console.ReadLine()); Console.WriteLine("Enter the y: "); b = double.Parse(Console.ReadLine()); result5 = percentage.Percent(a, b); Console.WriteLine("Percentage: " + result5 + "%"); } else { Console.WriteLine("Ending now!"); } }
public double MakeCalculation() { for (int i = 0; i < (numberSave.Count - 1); i++) { if (temptotal == 0) { x = numberSave[i]; } else { x = temptotal; } var f = numberSave[i + 1]; if (Operator[y] == "/") { r = Divide.divided(x, f); } else if (Operator[y] == "*") { r = Multiply.multiply(x, f); } else if (Operator[y] == "+") { r = Add.add(x, f); } else if (Operator[y] == "-") { r = Subtract.subtract(x, f); } y++; temptotal = r; } numberSave.Clear(); Operator.Clear(); y = 0; temptotal = 0; return(r); }
//THE MOTHER FUNCTION public int handledIt(string input) { //declare variable to hold result from operation int result = 0; //set stack_record so that I can access the last user input stack_record.lastQ = input; //create new expression class to handle parsing user input Expression myExp = new Expression(); //allow the container to be set from the parseExpression method Container answer = myExp.ParseExpression(input); //search the equation for a constant and parse it out to do the math on. string ContString = "abcdefghijklmnopqrstuvwxyz"; foreach (var letter in input) { if (ContString.IndexOf(letter) == 0) { Console.WriteLine("No Constant Defined"); } else { } } //shorthand the variables from Container class int lhs = answer.LHS; int rhs = answer.RHS; char op = answer.OP; string constant = answer.CONS; //run the operator logic if (op == '+') { Add add_me = new Add(); result = add_me.addIt(lhs, rhs); } else if (op == '-') { Subtract subtract_me = new Subtract(); result = subtract_me.subtractIt(lhs, rhs); } else if (op == '*') { Multiply multiply_me = new Multiply(); result = multiply_me.multiplyIt(lhs, rhs); } else if (op == '/') { Divide divide_me = new Divide(); result = divide_me.divideIt(lhs, rhs); } else if (op == '%') { Modulo modulo_me = new Modulo(); result = modulo_me.moduloIt(lhs, rhs); } else if (op == '=') { conts.Add(constant, rhs); result = rhs; } else { throw new InvalidOperationException("no valid operator found"); } //set stack_record result for later access stack_record.last = result; return(result); }
void CreateOperators() { // Only one of each operation Token needs to be created opAdd = new Add(workStack); opSubtract = new Subtract(workStack); opMultiply = new Multiply(workStack); opDivide = new Divide(workStack); opPower = new Power(workStack); opBracket = new Bracket(); opUnaryMinus = new UnaryMinus(workStack); opUnaryPlus = new UnaryPlus(); opSqrt = new Sqrt(workStack); opSin = new Sin(workStack); opCos = new Cos(workStack); opTan = new Tan(workStack); opLog = new Log(workStack); opAsin = new Asin(workStack); opAcos = new Acos(workStack); opAtan = new Atan(workStack); functions = new Dictionary<string, Function> { {"sqr", opSqrt }, {"sin", opSin }, {"cos", opCos }, {"tan", opTan }, {"log", opLog }, {"asin", opAsin }, {"acos", opAcos }, {"atan", opAtan } }; binaryOperators = new Dictionary<char, BinaryOperator> { {'+', opAdd }, {'-', opSubtract }, {'*', opMultiply }, {'/', opDivide }, {'^',opPower } }; }