We will understand by simple calculator, a program that parses a full line mathematical expression, evaluates it, and returns the result. The mathematical expression can contain any of the '*','/','+','-','(' signs. May it seem very simplistic, programming a simple calculator uses quite complex concepts. In a way, it tackles the difficulties you might encounter when creating a script compiler. Indeed, the idea is the same: to be able to interpret a mathematical expression and evaluate it, repecting the priority of operators. Therefore the expressions between '(' and ')' must be evaluated first and the '*' and '/' are always computed before '+' and '-'. Lets look at a few methods to achieve this.
Attachmentshow to program a calculator (5944-61110-how to program a calculator.doc)
|
No responses found. Be the first to respond and make money from revenue sharing program.
|