Coder Social home page Coder Social logo

stack-based-calculator's Introduction

Stack-based Calculator

A fully functional calculator that solves infix mathematical expressions that are represented in a string, tranforms it to postfix expressions and then calculates its result using two stacks, one for operands and the other for the operations.


Valid operations:

  • Basic operations like addition, subtraction, multiplication, and division.
  • Using parenthesis in expressions.
The Infix Expression: 1+2+(55)*(3/4*(99))+3*4
The Postfix Expression for the input is: 1 2 + 55 3 4 / 99 * * + 3 4 * +   
result = 4098.75
  • Power of both floating point and integer numbers.
The Infix Expression: (1+2*3)^2
The Postfix Expression for the input is: 1 2 3 * + 2 ^
result = 49
The Infix Expression: 2.3^3
The Postfix Expression for the input is: 2.3 3 ^
result = 12.167
  • Factorial (calculating factorial using a simple dynamic-programming function).
 The Infix Expression: 9!/8!
 The Postfix Expression for the input is: 362880 40320 /
 result = 9
  • Percentage.
The Infix Expression: 12%*12%
The Postfix Expression for the input is: 0.12 0.12 *
result = 0.0144
  • Using e (Euler's Number) and PI.
The Infix Expression: e^3
The Postfix Expression for the input is: 2.71828182845905 3 ^
result = 20.0855369231877
The Infix Expression: 3*PI/4
The Postfix Expression for the input is: 3 3.14159265358979 * 4 /
result = 2.35619449019234
  • tan, sin, cos (whether in radians or degrees as the user specifies in the start of the program).
The Infix Expression: tan45 + sin30 + cos60
The Postfix Expression for the input is: 1 0.5 + 0.5 +
result = 2
  • Square root.
The Infix Expression: sqrt100/sqrt25
The Postfix Expression for the input is: 10 5 /
result = 2

stack-based-calculator's People

Contributors

yahyaalaamassoud avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.