Question
This is C++ exercise (DATA STRUCTURE). Please show clearly all the work, and all the file including the output example of each question. Thanks. -
This is C++ exercise (DATA STRUCTURE). Please show clearly all the work, and all the file including the output example of each question. Thanks.
- Stacks and Queues Questions.
1a. Create two different stacks using one template Stack (array-based stack)
- Create only these two files: Stack.h & main.cpp
- In Stack.h, write a class generic Stack Specification using templates. EX :
// Stack.h
template
class Stack
{
private:
T stackItem[MAX_ITEMS];
int top;
public:
Stack() {top = -1;}
~Stack();
void makeEmpty() {top = -1}
bool isEmpty() {top = -1;}
bool isFull() {return tp == MAX_ITEMs -1;}
void push(T item ) {top++; stackItems[top] = item; }
void pop(T & item) [item = stackItems[top]; top--;]
};
- In the Driver.cpp, declare two Stack objects: intStack. The stack should hold up to 5 integer values. The other: stringStack . The stack should hold up to 5 string values.
- Enter integer values to be pushed into the intStack: Make sure to enter at least 5 numbers, so that the stack is full. Then the program will pop off the values and output them to the screen.
- Same thing with String values: Enter integer values to be pushed into the stringStack: Make sure to enter at least 5 strings, so that the stack is full. Then the program will pop off the values and output them to the screen.
---------------
1b. Stack of characters NOT using a template (array-based stack)
- Create 2 files: Stack.h and main.cpp
- in Stack.h, write a class Stack specification, but NOT using templates.
- In Driver.cpp file, declare a stack object name: stack and this stack should hold up to 5 character values.
- Enter characters to be pushed into the stack: Make sure to enter at least 5 characters, so that the stack is full. Then the program will pop off the values and output them to the screen
------------------
1c. Create two different queues using one template Queue
- Create 2 files : Queue.h & main.cpp
- in Queue.h write a class Queue specification using templates
- In Driver.cpp file, declare 2 queue object name: intQueue and this stack should hold up to 5 integer values. The other name: stringQueue, and hold up 5 string values.
- Enter integer values to be added to the intQueue: Make sure to enter at least 5 numbers, so that the queue is full. Then the program will remove Dequeue the numbers and output them to the screen.
- Enter string values to be added to the stringQueue: Make sure to enter at least 5 strings, so that the queue is full. Then the program will remove Dequeue the characters and output them to the screen.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started