Question: A. Implement all the member functions of the Stack class. B. Write the code for a main() function that test all the member functions. Note
A. Implement all the member functions of the Stack class.
B. Write the code for a main() function that test all the member functions. Note that you are ask to display at least the contents of the element removed from that Stack object.
#include
template
class Stack
{
friend ostream& operator<<(ostream&, const Stack
// Postcondition: displalys the top element stored on top of the Stack obj
public:
stack();
// Postcondition: creates an empty Stack object 5%
bool isEmpty();
// Postcondition: returns true if the Stack object is empty; false otherwise 5%
int size();
// Postcondition: returns the size or the # of elements that are stored in the stack 5%
void push(T&);
// Postcondition: a new T-type object is pushed onto the Stack object 10%
T& top();
// Postcondition: returns the object sitting on top of the Stack object 10%
void pop();
// Postcondition: if the Stack object is not empty, the top element is removed. 10%
private:
vector
};
Since the Stack class uses a vector type of data member as its underlying storage, your may need to uses ome or all of the following member functions of the vector class. The prototypes of these functions are provided below:
void push_back(T&);
// Postcondition: Inserts an element to the end of a vector; automatically increasing the container size by one.
T& back();
// Postcondition: if the vector is not empty, returns a reference to the last element of the vector
void pop_back();
// Postcondition: if the vector is not empty, removes the last element in the vector and automatically reducing the container size by one.
int size();
// Postcondition: returns the size or # of elements stored in the vector
bool empty();
// Postcondition: returns true if vector is empty; returns false otherwise
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
