What is the algorithm for simple calculator?

1 Answer

Answer :

A simple calculator works strictly left to right:get a number as the result of the last operation (if there is no number make it zero)make the result of the last operation the current numberget the next operatorif there is no next operator or it is equals (=) go to step 8get the next numberdo the operator on the current number and the next numbergo to step 2print the result of the last operatorstopYou need to: decide what to do if two operators are found together without an intervening number;decide how to detect a unary minus (ie when a '-' is found, is it a binary "number - number", or a unary "negate following number"how to handle the numbers - work with integers, fixed point or floating point, etc.decode the operator and do the relevant operation on the stored numbers.-----------------------------------A reverse polish calculator is actually much easier to code (than a simple calculator), but allows the user to specify precedence of operations (like a scientific calculator) or to use it as a simple calculator (left-to-right):Initialise the stackget an objectif no more objects go to step 12if the object is a number go to step 9if the are not at least 2 numbers on the stack errordo the operation on under and top (eg under ÷ top)remove the top two numbers and push the result on the stackrepeat from step 2if stack full errorpush the number on the stackrepeat form step 2If stack empty push 0 onto the stackprint top number on stackclear the stackstopA simple calculator would evaluate: "1 + 3 x 2" as "(1 + 3) x 2" = 4 x 2 = 8The reverse polish calculator would have the same calculation entered as "1 3 + 2 x"

Related questions

Description : Which allows for a simple and matrix implementation of all the basic algorithm? a) HMM b) Restricted structure of HMM c) Temporary model

Last Answer : b) Restricted structure of HMM

Description : The minimax algorithm computes the minimax decision from the current state. It uses a simple recursive computation of the minimax values of each successor state, directly implementing the defining equations. The ... are backed up through the tree as the recursion unwinds. a) True b) False

Last Answer : a) True

Description : The BACKTRACKING-SEARCH algorithm in Figure 5.3 has a very simple policy for what to do when a branch of the search fails: back up to the preceding variable and try a different value for it. This is ... also possible to go all the way to set of variable that caused failure. a) True b) False

Last Answer : a) True

Description : Which algorithm are used depending on the size of the numbers: a. Simple algorithm b. Specific algorithm c. Both d. None of these

Last Answer : b. Specific algorithm

Description : Which algorithm is used for matrix multiplication: a. Simple algorithm b. Specific algorithm c. Strassen algorithm d. Addition algorithm

Last Answer : c. Strassen algorithm

Description : Which algorithm is a divided and conquer algorithm that is asymptotically faster: a. Simple algorithm b. Specific algorithm c. Strassen algorithm d. Addition algorithm

Last Answer : c. Strassen algorithm

Description : Which algorithm is used to find GCD of two integers. a. Multiplication algorithm b. Division algorithm c. Addition algorithm d. Simple algorithm

Last Answer : b. Division algorithm

Description : Which algorithm is used as a general variant of a theorems, in the domain of integral numbers: a. Multiplication algorithm c. Addition algorithm d. Simple algorithm

Last Answer : c. Addition algorithm

Description : Consider a line AB with A = (0,0) and B = (8, 4). Apply a simple DDA algorithm and compute the first four plots on this line. (1) [(0, 0), (1, 1), (2, 1), (3, 2)] (2) [(0, 0), (1, 1.5), (2, 2), (3, 3)] (3) [(0, 0), (1, 1), (2, 2.5), (3, 3)] (4) [(0, 0), (1, 2), (2, 2), (3, 2)]

Last Answer : [(0, 0), (1, 1), (2, 1), (3, 2)] 

Description : How to use a TI-89 calculator to simplify simple expressions?

Last Answer : I dont know but would this be any help http://oakroadsystems.com/math/polysol.htm good luck!

Description : What is a simple mortgage calculator?

Last Answer : A simple mortgage calculator is a tool used to calculate mortgage payments. It simplifies the compound interest process to give users a single payment number.

Description : Is a simple interest loan calculator simple?

Last Answer : Yes, usually these calculators just allow you to put in the principal amount of the loan, number of months the loan is over, and the interest rate and it helps you figure out your problems.

Description : Where can I find a good simple interest loan calculator?

Last Answer : Almost certainly there is one available on you bank's web site as most banks offer this service these days. If the one your bank provides seems too complex for you, try the calculators provided by other banks to see which one you like best.

Description : Which of the following is not an example of a “small-scale embedded system”? A. Electronic Barbie doll B. Simple calculator C. Cell phone D. Electronic toy car

Last Answer : C. Cell phone

Description : Which of the following is not an example of a “small-scale embedded system”? A. Electronic Barbie doll B. Simple calculator C. Cell phone D. Electronic toy car

Last Answer : Electronic barbie doll