// FILE: charstack.h // ________________________________________________________________________ // // CONSTRUCTOR for the CharStack template class: // CharStack( ) // Postcondition: The stack has been initialized as an empty stack. // // MODIFICATION MEMBER FUNCTIONS for the CharStack class: // void push(const char& entry) // Precondition: size( ) < CAPACITY. // Postcondition: A new copy of entry has been pushed onto the stack. // // void pop( ) // Precondition: size( ) > 0. // Postcondition: The top char of the stack has been removed. // // CONSTANT MEMBER FUNCTIONS for the CharStack class: // bool empty( ) const // Postcondition: Return value is true if the stack is empty. // // size_type size( ) const // Postcondition: Return value is the total number of chars in the stack. // // char top( ) // Precondition: size( ) > 0. // Postcondition: The return value is the top char of the stack but the // stack is unchanged. // // VALUE SEMANTICS for the CharStack class: // Assignments and the copy constructor may be used with CharStack // objects. #ifndef CHARSTACK_H #define CHARSTACK_H #include // Provides size_t class CharStack { public: // TYPEDEFS AND MEMBER CONSTANT typedef size_t size_type; typedef char value_type; enum { CAPACITY = 30 }; // CONSTRUCTOR CharStack( ) { used = 0; } // MODIFICATION MEMBER FUNCTIONS void push(const char& entry); void pop( ); // CONSTANT MEMBER FUNCTIONS bool empty( ) const { return (used == 0); } size_type size( ) const { return used; } char top( ) const; private: char data[CAPACITY]; // Partially filled array size_type used; // How much of array is being used }; #endif