Stack is implemented using arrays. Create a new stack class that extends vector. Note that the vector is now the storage for data in the stack. A stack is a vector, because stack extends vector. Draw the UML diagram for the classes. Implement it.

```
template
class Stack
{
public:
Stack();
bool empty() const;
T peek() const;
void push(T value);
T pop();
int getSize() const;

private:
T elements[100];
int size;
};
```




```

#include

#include

using namespace std;



#ifndef STACK_H

#define STACK_H



template

class Stack: public vector

{

public:

Stack();

bool empty();

T peek();

void push(T value);

T pop();

int getSize();

};



template

Stack::Stack()

{

}



template

bool Stack::empty()

{

return getSize() == 0;

}



template

T Stack::peek()

{

if (empty())

throw runtime_error("Stack is already empty");



return at(getSize() - 1);

}



template

void Stack::push(T value)

{

push_back(value);

}



template

T Stack::pop()

{

if (empty())

throw runtime_error("Stack is already empty");



Computer Science & Information Technology

You might also like to view...

If method Replace has four arguments then the third argument must be:

a) the character to be replaced b) the new character c) the index at which to begin d) the count

Computer Science & Information Technology

Write a complete program that calculates and displays the product of three integers. Add comments to the code where appropriate. [Note: You’ll need to write the necessary using declarations or directive.]

What will be an ideal response?

Computer Science & Information Technology

What is Information architecture?

What will be an ideal response?

Computer Science & Information Technology

The interactive labels, called ____, appear when you position the mouse pointer over the label.

a. erasers b. reference points c. widgets d. scrubby sliders

Computer Science & Information Technology