EP 241 Computer Programming
 


EP241 - Homework


Calculator

Write a program that reads a string of arithmetic expression from the keyboard and evaluates the arithmetic operation in the string.
Some example runs are given below.
Your program should accept only
* any real or integer numbers
* four basic arithmetic operators, +, -, *, /
* paranthesis ( , )

Example outputs:

  Input an aritmetic expression:  1 + 1.3
  The result is  2.3

  Input an aritmetic expression:  2 - 3 * 4 + 2
  The result is  -8

  Input an aritmetic expression:  (5 + (11-5) * 2) * 4 + 9.9
  The result is  77.9

  Input an aritmetic expression:  2 + 3 = 5
  Error: Undefined symbol '='

  Input an aritmetic expression:  (5 + (11-5 * 2) * 4 + 9
  Error: Missing paranthesis ')'

  Input an aritmetic expression:  (5 + 11-5) * 2) * 4 + 9
  Error: Missing paranthesis '('

  Input an aritmetic expression:  2 - p 4 + 2
  Error: Undefined symbol 'p'

  Input an aritmetic expression:  2 - [3.0 / 4] + 2.5
  Error: Undefined symbol '['

University of Gaziantep - Department of Engineering Physics (2005 - 2024)