Department of Electrical and Computer Engineering
University of Texas at Austin
EE 379K, Fall 2000
Y. N. Patt, Instructor
TAs: Kathy Buchheit, Laura Funderburg, Chandresh Jain, Onur Mutlu, Danny Nold, Kameswar Subramanian, Francis Tseng, Brian Ward

Programming Assignment 5
Due: December 3, 2000 11:59 PM
 

Infix Calculator

Problem Statement

In this program, we ask you to design an infix calculator. The program should start by displaying a prompt for the user Input>. The user will then enter an arbitrary arithmetic expression, using only the operator + (denoting the binary operation of addition), the operator - (denoting the binary operation of subtraction), the left parenthesis, the right parenthesis, together with decimal valued integer operands. This expression should be entered using an infix notation (explained below). As this expression is entered, the program can begin evaluating the expression. Once entry of the expression is complete (i.e., after the user hits the "ENTER" key), the program should display the results of calculating the arithmetic expression entered, followed by a new prompt for further user input. When the user types "x" in response to the prompt for further input, the program should display "Have a nice day!" and terminate.
 

Infix Notation

Most people are accustomed to writing arithmetic expressions in INFIX notation, in which case an operator that denotes a binary operation appears BETWEEN the two operands, as in

( 2 + 3 )
Using nested parentheses, we can represent more complex expressions such as
( 11 + ( ( 19 + 23 ) - ( 4 + 10 ) ) )


Program Details


Sample Input/Output

Input> ( 101 - ( ( 23 + 31 ) + 74 ) )
-027

Input> ( 150 - ( 1 + 2 ) )
+147
Input> ( 1 - 1 )
+000
Input> ( ( 200 - ( ( ( ( ( 5 - 3 ) - 75 ) - 18 ) + 5 ) - 7 ) ) + 2 )
+295

Input> x
Have a nice day!
 

Writing and submitting your program