Question: // file: rpnCalculator.cpp // Simple RPN Calculator // This is incomplete #include // used in main() #include #include using namespace std; int main() // Simple

 // file: rpnCalculator.cpp // Simple RPN Calculator // This is incomplete#include // used in main() #include #include using namespace std; int main()

// file: rpnCalculator.cpp // Simple RPN Calculator // This is incomplete

#include // used in main() #include #include using namespace std;

int main()

// Simple interactive RPN calculator // Library facilities used: cin, cout, peek(), ignore() from stream.h // vector, stack, push(), top(), pop() from the STL { stack operands; stack temp;

double nextNumber; char nextOperation;

double operand1; double operand2;

cout

while ( cin && cin.peek() != EOF ) { char ch = cin.peek();

switch ( ch ) { // digit or decimal point case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '.': cin >> nextNumber; operands.push( nextNumber ); break;

// arithmetic operation case '+': case '-': // case '*': // case '/': cin >> nextOperation;

// handle unary minus if ( ( cin.peek() >= '0' && cin.peek() >nextNumber; operands.push( -nextNumber ); break; }

// do binary operation if ( operands.size()

switch ( nextOperation ) { case '+': operands.push( operand1 + operand2 ); break; case '-': operands.push( operand1 - operand2 ); break; }

cout

break;

// display stack operation // case ':':

// ignore other characters default: cin.ignore(); break; }

if (ch == 'q') break; }

// report errors if ( operands.size() > 1 ) { cout

return 0; // normal exit code }

// file: revString.cpp // String manipulation example // This is incomplete

#include #include // for string streams #include using namespace std;

// MAX_INPUT is the maximum number of characters that we allow to be // read into a string object with istream::getline() static const int MAX_INPUT = 256;

int main() { char buf[MAX_INPUT]; string line = ""; string word;

cout

/* The following would be the best way to read in a line into a string * object; however, there is a bug in the code provided by MSVC that * reads an extra character (so the user would have to hit return twice. * - see http://support.microsoft.com/support/kb/articles/Q240/0/15.ASP

getline( cin, line );

*/

// The following is a workaround, use istream::getline() instead of // the function getline. cin.getline( buf, MAX_INPUT ); line = buf; // open a stream bound to the line istrstream input( line.c_str() );

while ( input >> word ) { cout

return 0; }

In-lab Exercises RPN calculator The RPN calculator program can only add and subtract. Other operations need to be added in. Your tasks are to do the following: Create a file lab11rpn.cppdirectory and copy the contents of ncalculator.c nto that. Build the executable and test the program Add multiplication and division operations to the calculator Add an operation that displays the contents of the operand stack in the order they were pushed. Here is a sample run of the program: No operands in the stack operand. 1 operand. 2 operand. 3 operand. 1 operand. 5 operand. 6

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!