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

implement the Stack ADT (50 points) using array – based approach #include \"Stac

ID: 3794653 • Letter: I

Question

implement the Stack ADT (50 points) using array – based approach

#include "StackArray.h"

template <typename DataType>
StackArray<DataType>::StackArray(int maxNumber)
{
}

template <typename DataType>
StackArray<DataType>::StackArray(const StackArray& other)
{
}

template <typename DataType>
StackArray<DataType>& StackArray<DataType>::operator=(const StackArray& other)
{
}

template <typename DataType>
StackArray<DataType>::~StackArray()
{
}

template <typename DataType>
void StackArray<DataType>::push(const DataType& newDataItem) throw (logic_error)
{
}

template <typename DataType>
DataType StackArray<DataType>::pop() throw (logic_error)
{

}

template <typename DataType>
void StackArray<DataType>::clear()
{
}

template <typename DataType>
bool StackArray<DataType>::isEmpty() const
{
   return false;
}

template <typename DataType>
bool StackArray<DataType>::isFull() const
{
   return false;
}

template <typename DataType>
void StackArray<DataType>::showStructure() const

// Array implementation. Outputs the data items in a stack. If the
// stack is empty, outputs "Empty stack". This operation is intended
// for testing and debugging purposes only.

{
if( isEmpty() ) {
   cout << "Empty stack." << endl;
}
else {
   int j;
   cout << "Top = " << top << endl;
   for ( j = 0 ; j < maxSize ; j++ )
   cout << j << " ";
   cout << endl;
   for ( j = 0 ; j <= top ; j++ )
   {
   if( j == top )
   {
   cout << '[' << dataItems[j] << ']'<< " "; // Identify top
   }
   else
   {
       cout << dataItems[j] << " ";
   }
   }
   cout << endl;
}
cout << endl;
}

#ifndef STACKARRAY_H
#define STACKARRAY_H

#include <stdexcept>
#include <iostream>

using namespace std;

#include "Stack.h"

template <typename DataType>
class StackArray : public Stack<DataType> {
public:
StackArray(int maxNumber = Stack<DataType>::MAX_STACK_SIZE);
StackArray(const StackArray& other);
StackArray& operator=(const StackArray& other);
~StackArray();

void push(const DataType& newDataItem) throw (logic_error);
DataType pop() throw (logic_error);

void clear();

bool isEmpty() const;
bool isFull() const;

void showStructure() const;

private:
int maxSize;
int top;
DataType* dataItems;
};

#endif       //#ifndef STACKARRAY_H

Explanation / Answer

#include<iostream>
#include<conio.h>
#include<stdlib.h>
using namespace std;
class stack
{
             int stk[5];
             int top;
      public:
             stack()
              {
                top=-1;
               }
             void push(int x)
              {
                 if(top > 4)
                       {
                           cout <<"stack over flow";
                           return;
                       }
                 stk[++top]=x;
                 cout <<"inserted" <<x;
               }
             void pop()
               {
                  if(top <0)
                   {
                         cout <<"stack under flow";
                         return;
                    }
                    cout <<"deleted" <<stk[top--];
                }
             void display()
               {
                   if(top<0)
                    {
                            cout <<" stack empty";
                            return;
                    }
                    for(int i=top;i>=0;i--)
                    cout <<stk[i] <<" ";
                }
};

main()
{
int ch;
stack st;
while(1)
{
cout <<" 1.push 2.pop 3.display 4.exit Enter ur choice";
cin >> ch;
switch(ch)
{
               case 1: cout <<"enter the element";
                        cin >> ch;
                        st.push(ch);
                        break;
               case 2: st.pop(); break;
               case 3: st.display();break;
               case 4: exit(0);
               }
         }
return (0);
}

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