Define a class named Calculation RPN that implements the following method: class
ID: 441658 • Letter: D
Question
Define a class named Calculation RPN that implements the following method: class CalculatorRPN { public: CalculatorRPN(); / / constructor void enter (double x); // push a value void add() ; //add two numbers void sub(); //subtract two numbers void mul(); //multiply two numbers void div(); //divide two numbers void neg(); //negate stack top void sqrt(); //square root of stack top double result(); //return stack top (peek) private: DoubleStack stack; //the calculation stack } The constructor creates a DoubleStack and maintains a pointer to it in a private data member. The add, sub, mul, and div are binary operators. They pop the top two numbers off the stack, perform a binary arithmetic operation, and push the result. The neg and sqrt are unary operators. They pop the top number, operate on it, and push the result. Write a main program to perform some calculations: CalculationRPN c = new CalculatorRPN(); CalculatorRPN c = new CalculatiorRPN (); // calculate -(3 + 4) * (9 - 2) // RPN version; where is unary minus enter (3); enter (4); add(); neg(); enter(9); enter(2); sub(); mul()Explanation / Answer
What kind of help you are expecting
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.