Answered step by step
Verified Expert Solution
Question
1 Approved Answer
c++ calculator Goal Develop a program that implements a four-function calculator that performs all arithmetic with fractions. Details Your program will read a list of
c++ calculator
Goal Develop a program that implements a four-function calculator that performs all arithmetic with fractions. Details Your program will read a list of arithmetic expressions, evaluate them and display their results. All numbers in the expression will be integers; however, the results of calculations will be fractions. Your program must be able to process any valid arithmetic expression that includes the following: Nonnegative integer numbers . The four basic arithmetic operations Parentheses Variable names, up to 100 variables, names follow C++ naming rules Assignment in the form var = expression For each expression, evaluate it. display the result and store the result in the appropriate variable. if necessary Required Objects A calculator needs two Stack objects -- one to store numbers and one to store operators. In this program, the number stack - the numStack - will store Fraction objects and the operator stack -- the opStack - Will store characters. In order to store and retrieve variable values, a Dictionary object will be necessary. The keys are strings and the values are Fractions. The exact implementation of the variable dictionary does not matter. Calculator Algorithm The program must read multiple lines from the standard input. Each line contains an arithmetic expression and possibly an assignment to a variable. An algorithm for processing such a line follows In Algorithms 1 and 2 2 3: 5: 6: A is an empty string 8: 9: 11: Algorithm 1 Main calculator algorithm 1: procedure EVALUATE(string s) Clear numStack Clear opStack Push $ onto opStack first-o dest-A 7 Scan forward for = symbol if = is found then first-position of character after = 10: dest -- first name found on line end if while first 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