Git Product home page Git Product logo

ios-apps-calculator's Introduction

Calculator

A calculator app written in swift that performs basic arithmetic functions.

Rough Algorithm Overview

  1. Create an array that will contain the entered numbers that are to be equated. (In this case: operandStack)

  2. When a number is added and an operation is pressed,

a. Get the current number

b. Reset the text field and get the operation requested

c. Send the current number to the array (operandStack) using the method - pushOperand()

  1. When another number has been entered and the "=" sign has been pressed,

a. Get the entered number and add it to the array (operandStack) using pushOperand()

b. Call the method to perform the operation (performOperation) that takes the type of operation as an argument (i.e "+", "-", "*", "/")

c. In performOperation(),

Based on the operation sent, the method popOperand() is called as follows:
switch operation
        {
            case "+": result = self.popOperand() + self.popOperand()
            case "-": result = self.popOperand() - self.popOperand()
            case "x": result = self.popOperand() * self.popOperand()
            case "/": result = self.popOperand() / self.popOperand()
            default: break
        }

d. In popOperand(), The first number in the array (operandStack) is returned and deleted from the operandStack

That way, we are returned with both the numbers in the operandStack when we performOperation()

e. Finally, the result of the operation is added to the operandStack by calling pushOperand() once again.

This way, the result of the operation is stored and can be used to perform other operations

ios-apps-calculator's People

Contributors

sachinkesiraju avatar mukeshinnoventes avatar mukeshthawani avatar

Watchers

James Cloos avatar PKCodeBox avatar  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.