Question
#include RPNCalculator.hpp #include // you may include more libraries as needed using namespace std; /* * Purpose: Determine whether some user input string is a
#include "RPNCalculator.hpp" #include
using namespace std;
/* * Purpose: Determine whether some user input string is a * valid floating point number * @param none * @return true if the string s is a number */ bool isNumber(string s) { if(s.size() == 1 && s == "-") return false; else if(s.size() > 1 && s[0] == '-') s = s.substr(1);
bool point = false; for(int i = 0; i
return true; }
int main() { Operand* temp = new Operand;// TODO - Declare a stack to hold the operands cout
while(true) { cout "; /* TODO 1. Read input (operators and operands) until you encounter a "=" 2. Use the isNumber function to check if the input is an operand 3. push all operands to the stack 4. If input is not an operand, call the compute function to evaluate the partial expression */
}
/* TODO - If the stack is empty then print "No operands: Nothing to evaluate" */
/* TODO - Validate the expression 1. If valid then print the result 2. Else, print "Invalid expression"*/
return 0; }
Please test it, Attached are the instructions for the main file. If you need anything else just ask.
RPNCalculator main driver file Create a stack by instantiating an RPNCalculator object Prompt the user to enter the operators and operands using the print statement, "Enter the operators and operands ('+'-') in a postfix format" Read user inputs (Tip: use getline for all inputs) until "-" is entered. If the input is a number (isNumber function provided in starter code) then push it onto the stack, else, call the compute function on the input When your program reads"" If the stack is empty print "No operands: Nothing to evaluate" and return If the expression is invalid print "Invalid expression" and return. An expression is considered valid if there is exactly one item left on the stack. (Hint: pop the last item and check if the stack is empty) *Otherwise, print the result of the expression (for floating numbers limit the precision to 4 decimals) Below are some sample outputs SAMPLE OUTPUT 1 Enter the operators and operands ('+', '*") in a postfix format #> 2.5 #> 3 #> 2.4 13.2 SAMPLE OUTPUT 2 Enter the operators and operands ('+', '*") in a postfix format 15 #> 25 RPNCalculator main driver file Create a stack by instantiating an RPNCalculator object Prompt the user to enter the operators and operands using the print statement, "Enter the operators and operands ('+'-') in a postfix format" Read user inputs (Tip: use getline for all inputs) until "-" is entered. If the input is a number (isNumber function provided in starter code) then push it onto the stack, else, call the compute function on the input When your program reads"" If the stack is empty print "No operands: Nothing to evaluate" and return If the expression is invalid print "Invalid expression" and return. An expression is considered valid if there is exactly one item left on the stack. (Hint: pop the last item and check if the stack is empty) *Otherwise, print the result of the expression (for floating numbers limit the precision to 4 decimals) Below are some sample outputs SAMPLE OUTPUT 1 Enter the operators and operands ('+', '*") in a postfix format #> 2.5 #> 3 #> 2.4 13.2 SAMPLE OUTPUT 2 Enter the operators and operands ('+', '*") in a postfix format 15 #> 25Step 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