Implement the following function. You may use the stack template class (pasted below) and the stack operations of push, pop, peek, is_empty, and size. You may also use cin.peek( ) and use "cin>>i" to read an integer.

int evaluate_postfix_from_cin( )
// Precondition (Which is not checked): The next input line of cin is a properly formed postfix expression consisting of integers and the binary operations
// Postcondition: The function has read the next input line (including the newline) and returned the value of the postfix expression.

Test it in the main()

// FILE: stack1.template
// This file is included in the header file, and not compiled separately.
// INVARIANT for the stack class:
// 1. The number of items in the stack is in the member variable used.
// 2. The actual items of the stack are stored in a partially-filled
// array data[0]..data[used-1]. The stack elements appear from the
// bottom (at data[0]) to the top (at data[used-1]).
#include // Provides assert
namespace main_savitch_7A
{
template
const typename stack::size_type stack::CAPACITY;

template
void stack::push(const Item& entry)
// Library facilities used: cassert
{
assert(size( ) < CAPACITY);
data[used] = entry;
++used;
}

template
void stack::pop( )
// Library facilities used: cassert
{
assert(!empty( ));
--used;
}
template
Item stack::top( ) const
// Library facilities used: cassert
{
assert(!empty( ));
return data[used-1];
}
}
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.