3/3/2023 0 Comments Calculadora pascal program![]() ![]() The brackets are special, in that they work on a sub-array. I assume the latter in what follows, but the concepts work either way. ) type tElement = record element_type: tType number: integer end This is how I would do it (if forced to use an array), but if it is beyond you just stick to an array of strings. ![]() So you could have an array of string, where each element is either a number or an operator: '5', '+', '3', '*', '5', '-', '2' Or you could have an array of some record type that tells you whether it is a number or an operator, say: type tType = (number, add, subtract, multiply. Now, you are supposed to store the expression in an array. I start with 5 + 3 * 5 -2 The most precedent operator is *, so: 5 + 3 * 5 -2 5 + 15 -2 The remaining operators have equal precedence, so I'll just take them left to right: 5 + 15 -2 20 -2 and 20 -2 18 There are no more operators, so the answer is 18. ![]() So, according to your assignment description, you account for operator precedence by evaluating the same expression over and over until there is only a number (or error): ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2023
Categories |