Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this practice assignment you will be writing simple array based stacks and q

ID: 3744062 • Letter: F

Question

For this practice assignment you will be writing simple array based stacks and queues. Your classes should be templated and they should inherit from the following virtual base classes. Note that for templated classes, the methods have to be put in the header files, not in a separate source file. Your classes should be called ArrayStack and ArrayQueue and they should be in files called ArrayStack.h and ArrayQueue.h.

template <typename T>

class Stack {

public:

virtual ~Stack() {}

virtual void push(const T &t) = 0;

virtual T pop() = 0;

virtual T peek() const = 0;

virtual bool isEmpty() const = 0;

};

template <typename T>

class Queue {

public:

virtual ~Queue() {}

virtual void enqueue(const T &t) = 0;

virtual T dequeue() = 0;

virtual T peek() const = 0;

virtual bool isEmpty() const = 0;

};

Make sure that your classes have appropriate copy constructors and assignment operators. These can work with the ArrayStack and ArrayQueue types and not the supertypes to keep things simple for you. For performance reasons you might consider implementing a move methods, but that isn't required to pass the test code. You are not allowed to use any of the standard collections for this assignment. So no vector, deque, list, etc.

free memory appropriately!!!

Can someone explain where I should start on this assignment. I find it somewhat daunting. It would be helpful if someone could disect and explain the starter code and then show me what my code should look like --maybe focusing just on stack so that way I can practice with a queue.

Explanation / Answer

//In header file just declare the class name function names and all

//header file code

#include<iostream>
#include<fstream>
using namespace std;
class Stack
{
int top;
public:
int a[MAX]; //Maximum size of Stack
  
Stack();
void push(int x);
int pop();
int peek();
bool isEmpty();
};

// now in cpp file define the functions given in header file

#include <Arraystack.h>

  

void Stack::push(int x)

{

if (top >= (MAX-1))

{

cout << "Stack Overflow";

return ;

}

else

{

a[++top] = x;

return ;

}

}

  

int Stack::pop()

{

if (top < 0)

{

cout << "Stack Underflow";

return 0;

}

else

{

int x = a[top--];

return x;

}

}

  

bool Stack::isEmpty()

{

return (top < 0);

}

  

Stack::Stack()

{

top = -1;

}

int Stack::peek()

{

if(top==-1)

cout<<"Stack empty exception"<<endl;

return -1;

return a[top];

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote