Click here to Skip to main content
13,448,170 members (54,589 online)
Click here to Skip to main content
Add your own
alternative version


49 bookmarked
Posted 27 Jan 2007

A multipurpose scientific calculator

, 17 Apr 2008
Rate this:
Please Sign up or sign in to vote.
A calculator handling complex numbers and scientific functions

Sample Image - scientific_calculator.jpg


This is a scientific calculator involving many functions such as:

  1. Normal arithmetic operations.
  2. Functions such as factorial, permutation, combination etc.
  3. Scientific functions (sin, cos, sin-1, cos-1, sinh, cosh, sinh-1,etc.).
  4. Operations on complex numbers.
  5. Storage of values in variables and operations on these variables.
  6. Use of abbreviated form of representing values (such as m for milli, M for mega, etc.).
  7. Evaluation of simple series.
  8. Expressions involving any combination of the above.

Concepts used

Recursive parser:

The calculator uses a recursive parser for evaluation of expressions. A part of the recursive parser is represented in the diagram below. The parser uses a proper operator precedence. The complete precedence can be known by looking at the code.

Sample image - parser.jpg

Advantage of using the parser for expression evaluation

The complexity of procedure required is broken into many parts thus making each part simpler to understand and the overall structure robust. It becomes easier to to change the operator precedence implemented.

An alternative approach

We might use a stack to do the expression evaluation. But then, breaking down of the complexity to many procedures is not as straightforward as in the recursive function approach and we might stand to lose the advantages of the recursyve function approach.

Some Special Features

Easy-to-use interface

The calculator provides an easy-to-use interface. The expressions can be entered easily using the keyboard or by clicking the buttons using the mouse. For expressions using variables(X,Y,A,B,etc.) and symbols like pi(π), it is better to use the mouse since these characters are special characters.

Display of evaluated value in fraction form

Values of expressions can be viewed in normal decimal form or in the fraction form. Default is the decimal form. To change to fraction form check the option fraction in the toolstrip menu options->display.

Display of evaluated value in polar form

Complex numbers can be viewed either in the default form(a+bi) or in the form rLθ. To change to polar form, check the option polar in the toolstrip menu options->display.

Angle measurements in different units

Angle measurements may be in degree, radian, or grade. The selection may be done using the DomainUpDown at the top right of the main form. This selection effects the trignometric calculations as well as the measure of amplitude of complex numbers when they are displayed in polar form. The expression in the expression textbox is re-evaluated as soon as a change in the choice in the DomainUpDown is made.

Memory calculations

Answer memory

    • Whenever a value appears on the value textbox, it automatically updates Ans memory contents by storing the result.
    • The value can be used in the next expression using the variable Ans at any position of the expression.
    • Ans memory is not updated in case of error in evaluation.


    • The calculator provides 9 memory varaibles.
    • Values can be stored in these variables and they may be used later in expressions.
    • The values remain stored in the computer in a file even after closing the application and retain the values the next time we run the application.
    • The value stored in variables can be that of real numbers or co mplex numbers.


We may evaluate series such as sum of first ten natural numbers, or product of even numbers from 20 to 40.

How to use

    1. Just run the demo project. To do this, download the file Unzip the file. Run the file scientific_calculator_demo/release/calculator.
    2. Enter any expression as stated earlier.
    3. Press = button, or hit the = or [Enter] key on the keyboard to see the answer. If the answer is lenghty scroll down the textbox to view the complete answer.

To store values in variables and use them

      1. Check the mem radio button.
      2. We may directly add or subtract to the memory variables. Depending on whether store,add or subtract checkboxes are checked, values are stored to, added to or subtracted from the variables whose buttons are clicked. If none of check boxes on the memory variables-form are checked, a hit on a button in this form inserts corresponding variable to the expression.
      3. The memory variables may contain real values or complex values.

To evaluate expressions containing trignometric functions

    1. Check the Trignometry radio button.
    2. Now, to simply click the button in the trignometry form to get the funcions to the expression.
    3. To get the inverse functions to the expression click inv checkbox and then the button of the trignometric function whose inverse is required in the expression.

To evaluate expressions containing series

    1. Check the series radio button.
    2. Enter the lower value of the variable in the series expression in expression textbox and check Setlow and then I button. Similarly set the high value of the variable in the sries expression.
    3. The upper and lower limit of the variable have to be integers and upper limit should be greater than lower limit numerically.
    4. Now enter the expression containing the series expression and press = to view the result.
    5. For example, to find sum of first ten natural numbers:type 1 -> Setlow -> I; type 10 -> Sethigh -> I; type "SΣI"->=;to view the answer 55 in value textbox.
    6. At present, for all SΣ and Sπ that appear in a single expression, the range of variable will be same. With a further enhancement, we may get rid of this limitation.

Android app

Here is an android app that uses the same parser mentioned in this article: Calculator on Google Play. The only difference is that the App implements the same parser in JS and uses PhoneGap.


Here is a website that uses the same parser mentioned in this article:

About me

You can visit my webpage to know more about me.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Technical Lead Yahoo!
India India
I've studied info. sc. engg. from Sir MVIT, Bangalore.

I'm interested in programming.

Some of my technical blogs:

I also enjoy writing some webpages such as

More about me at and

You may also be interested in...

Comments and Discussions

QuestionFor knowledge and appreciation why didn't you post the project Pin
avner_simon21-Feb-07 0:20
memberavner_simon21-Feb-07 0:20 
AnswerRe: For knowledge and appreciation why didn't you post the project Pin
kbsbng22-Feb-07 20:50
memberkbsbng22-Feb-07 20:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02-2016 | 2.8.180318.3 | Last Updated 18 Apr 2008
Article Copyright 2007 by kbsbng
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid