## Calculator using variable names

I’ve recently been assigned an assignment to create a word calculator, and given my knowledge in python is still quite lacking, I want to ask if anybody has any better ideas for any possible solutions. The question is here: Jimmy has invented a new kind of calculator that works with words rather than numbers. Input … Read more

## OO design of Reverse Polish Notation Calculator

This solution focuses on the design of classes, not the actual push and pop stack part. I will include that part of the code as well. The current code has 2 operators (plus and minus). If we add another subclass under Token, is there a way that we don’t need to check in processInput() what … Read more

## Infix to postfix notation in Haskell (Shunting-yard algorithm)

I’ve written an infix to postfix converter in Haskell using the Shunting-yard algorithm. Example of how it works: \$ ./in2post 2 + 2 2 2 + \$ ./in2post 1 + 2 * 3 1 2 3 * + \$ ./in2post (5 – 4) * 3+1005/(12-6*(12 -8) ) 5 4 – 3 * 1005 12 6 … Read more

## RPN-Stack-Based Recursive Calculator Needs Tuneup

This function takes an array of strings and numbers and recursively processes it as a kind of “calculating program”. The structure is based on Reverse Polish Notation, so the top object in the stack (last in the array) determines what to do with the next one (or two) items in the program. For example, if … Read more

## Calculator parsing S-expressions

The following program is supposed to be a (command line) calculator that parses expression following syntax similar to Lisp’s S-expressions. Some examples: \$ echo “(+ 5 5)” | ./a.out 10.000000 \$ echo “(+ (- 3 2) (* 9 2))” | ./a.out 19.000000 \$ echo “(/ 24 6 2)” | ./a.out 2.000000 \$ echo “(/ 24 … Read more

## Refactoring calculator expression

I was doing a simple exercise to calculate the amount based on an expression. For example: (((2*2)+(3*5/5)+(2*5))) outputs 17 ((2*2)(3*5/5)(2*5)) output 120 etc I have written the code, but I am not satisfied with what I’ve done. Could you please help me to review the code and suggest the best approach for that? import java.util.ArrayList; … Read more

## Reverse Polish Calculator in Go

I’m very new to Go (this is my first real program), and I was hoping to see if there was anything I was missing about the language or any ways to make it more idiomatic. calculator.go package calculator import ( “../stack” “unicode” “strconv” ) func Calculate(input string) int { stack := new(stack.Stack) for i := … Read more

## NASM RPN Calculator

I’ve been learning Assembly over the past few days, and I’ve made a simple RPN calculator. Here is the main logic of the program, excluding utility functions such as printing: %include “utilities.s” SECTION .data badOpMsg db “Unknown character: “, 0h badNumMsg db “Error parsing number: “, 0h badExprMsg db “Invalid expression supplied”, 0h SECTION .bss … Read more

## Evaluating given numbers and operations

The program reads in an operation, and then numbers, and does stuff to them based on that. Exercise number 1 at this linl For example, ./this_file sum 1 2 3 would yield 6 I’m fairly certain I don’t need all the #includes, but I had added them at some point to deal with a problem, … Read more

## Ruby infixed math parser

It only does expressions with 2 operands yet, but I’m wondering if there are any ways I can improve this: # infix.rb: parse infix-operated math expressions class String def is_number? true if Float(self) rescue false end end class InfixParser @operations = [ ‘/’, ‘*’, ‘+’, ‘-‘ ] testString = ‘(24 + 6) / 10 * … Read more