Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Objective: Become familiar with the stack abstract data type (ADT) and increase your experience with classes Program Description: Real calculators (such as my trusty 35+
Objective: Become familiar with the stack abstract data type (ADT) and increase your experience with classes Program Description: Real calculators (such as my trusty 35+ year old HP 25) use a form of mathematical notation known as reverse polish notation (RPN). At the heart of RPN is a stack, as discussed in lecture. An RPN calculator works by reading strings from the keyboard. As long as the strings are numbers, you place them on the stack (push). The value on the top of the stack is displayed at all times as a prompt to the user input. When you encounter an operator you pop the appropriate number of numbers from the stack, perform the operation, then push the result back on the stack. For example, to calculate 3.2 2.4 on an RPN calculator you would enter: [tonyls ./rpn RPN Calculator v.10 by Tony Opheim RPN (empty > 3.2 2.4 + RPN 5.6 > To divide 3.5 by 2 you would enter RPN 5.6 > 3.5 2 / RPN 1.75 > ps quit Stack contents: 1.75 5.6 RPN 1.75 > [tony Get the idea? The assignment is to write an RPN calculator that imple- ments the four basic math functions (addition, multiplication, subtraction, and division) and the following special functions: sq (square), sqrt (square root), dup (duplicates the top of the stack), swap (swaps the top two ele- ments of the stack), ps (print stack), and quit (exits your program). All numbers should be stored/manipulated as double. All appropriate error checking should be performed including invalid operations. The program should loop continuously for input until terminated with the quit keyword. The user interface should model the application demonstrated above exactly. Particularly note that input is processed a line at a time. Objective: Become familiar with the stack abstract data type (ADT) and increase your experience with classes Program Description: Real calculators (such as my trusty 35+ year old HP 25) use a form of mathematical notation known as reverse polish notation (RPN). At the heart of RPN is a stack, as discussed in lecture. An RPN calculator works by reading strings from the keyboard. As long as the strings are numbers, you place them on the stack (push). The value on the top of the stack is displayed at all times as a prompt to the user input. When you encounter an operator you pop the appropriate number of numbers from the stack, perform the operation, then push the result back on the stack. For example, to calculate 3.2 2.4 on an RPN calculator you would enter: [tonyls ./rpn RPN Calculator v.10 by Tony Opheim RPN (empty > 3.2 2.4 + RPN 5.6 > To divide 3.5 by 2 you would enter RPN 5.6 > 3.5 2 / RPN 1.75 > ps quit Stack contents: 1.75 5.6 RPN 1.75 > [tony Get the idea? The assignment is to write an RPN calculator that imple- ments the four basic math functions (addition, multiplication, subtraction, and division) and the following special functions: sq (square), sqrt (square root), dup (duplicates the top of the stack), swap (swaps the top two ele- ments of the stack), ps (print stack), and quit (exits your program). All numbers should be stored/manipulated as double. All appropriate error checking should be performed including invalid operations. The program should loop continuously for input until terminated with the quit keyword. The user interface should model the application demonstrated above exactly. Particularly note that input is processed a line at a time
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started