#include "Exception.h" class Stack{ private: int cap; int size; int* array; public: Stack(int = 5); ~Stack(); bool full(); bool empty(); int sum(); void push(int); int pop(); friend std::ostream &operator<<( std::ostream &, Stack const & ); }; Stack::Stack(int c):cap(c), size(0), array(new int[cap]){} Stack::~Stack(){ delete[] array; } bool Stack::full(){ return size == cap; } bool Stack::empty(){ return size == 0; } int Stack::sum(){ if( empty() ) throw underflow(); int result = 0; for(int i = 0; i < size; i++){ result += array[i]; } return result; } void Stack::push(int v){ if( full()) throw overflow(); array[ ++size ] = v; } int Stack::pop(){ if( empty() ) throw underflow(); return array[ --size ]; } std::ostream &operator<<( std::ostream &out, Stack const &stack ) { for ( int i = 0; i < stack.size; ++i ) { out << stack.array[i] << " "; } return out; }