Question
HP-35 Task Write a program to emulate calculations performed on the HP-35 calculator. This task is available for automatic testing using the name hp-35. Background
HP-35
Task
Write a program to emulate calculations performed on the HP-35 calculator. This task is available for automatic testing using the name hp-35.
Background The HP-35 was the first scientific hand-held calculator, released in 1972 and an immediate success with engineers and scientists. Amongst other features, it used an unusual way of entering numbers, called RPN. RPN (reverse Polish notation, named for Polish mathematician Jan Lukasiewicz) allows complex calculations to be entered without the use of parentheses. The key difference is that operators are entered after the operands, rather than between them.
The HP-35 implemented RPN using a stack of 4 registers, referred to as X, Y , Z, and T. The value in the X register is the one shown on the calculator's LED display; the other registers are used for temporary values during calculations. New values are entered into the X register, with existing values "pushed" up the register stack: the old value of X goes into Y, the old value of Y goes into Z, the old value of Z goes into T, and the old value of T is lost.
Single-operand functions (such as square root) use and replace the value in the X register; other registers are unchanged. Functions that operate on 2 values (such as the arithmetic operators) use the values in Y and X, with the result going back into X. Values in the Z and T registers are "dropped" down the stack, with Z overwriting the old Y and T overwriting the old Z. The value of T is preserved, providing a simple way to do calculations with repeated values.
This scheme allows calculations to be entered without using parentheses. For example, you could compute the compound expression (5 + 4)/(3 - 2) like this:
5 ENTER 4 + 3 ENTER 2 -
Hints
You'll need to define the class HPStack to represent the calculator's operand stack, with operations such as push (push all values up 1 level and store a value into X), pop (drop all values down 1 level and return the old X value), and peek (return the current X value). The simplest approach is to use an array to store the register values, with the methods manipulating the array elements. The calculator should read and process tokens representing numbers and operator keys, with the current value of the X register displayed after processing each line. It should exit when all lines of input have been processed.
Please answer each level of question seperately so i can understand how it built from start to end.
C++
netbeans as a compiler
A suitable main function will contain code such as this: HPStack stack; string line while (getline (cin, line)) stringstream expression (line)i string token while (expression >> token) if (isdigit (token [0])) stack.push (atof (token.data) else if (token""// other arithmetic ops similar double x = stack-pop(); double y = stack.pop(); stack.push(y x); coutStep 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