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

Language: C++ I need help making an array-based stack header file. In the ABS.h,

ID: 3755642 • Letter: L

Question

Language: C++

I need help making an array-based stack header file. In the ABS.h, the default scale factor is 2.0f and when you attempt to push() an item onto an ABS that is full, the capacity will get scaled by the scale factor and if the "percent full" (current size/max capacity) becomes less than 1/scalefactor, the capacity should decrease. I need to also create template<typename T>

The methods that are needed include:

ABS(): Default constructor. Capacity should be initialized to 1, and size should be initialized to 0.

ABS(int capacity): Constructor for an ABS with the specified starting capacity.

ABS(const ABS &d): Copy constructor.

ABS &operator=(const ABS &d): Assignment operator.

~ABS(): Destructor for an ABS.

void push(T data): Add a new item to the top of the stack.

T pop(): Remove the item at the top of the stack, and return its value. Throws -1 if the stack is empty.

T peek(): Return the value of the item at the top of the stack, without removing it. Throws -1 if the stack is empty.

unsigned int getSize(): Returns the current number of items in the ABS.

unsigned int getMaxCapacity(): Returns the current max capacity of the ABS.

T* getData(): Returns the array representing the stack. This should only be used in order to implement the copy constructor or assignment operator.

Explanation / Answer

#ifndef _ABS_H_

#define _ABS_H_

#include <iostream>

using namespace std;

template <class T>

class ABS {

public:

ABS():current_size(0) {

scale_factor=2.0;

this->STACK=new T [current_size+1];

capacity=current_size+1;

}

ABS(int capacity)

{

scale_factor=2.0;

current_size=0;

this->STACK=new T [current_size+1];

this->capacity=capacity;

}

ABS(const ABS &d)

{

this->STACK=d->STACK;

this->current_size=d->current_size;

this->capacity=d->capacity;

}

ABS &operator=(const ABS &d)

{

ABS A=ABS();

A.STACK=d.STACK;

A.current_size=d.current_size;

A.capacity=d.capacity;

return A;

}

~ABS()

{

delete STACK;

cout<<"OBJECT DELETED"<<endl;

}

void push (T data);

T pop();

const T& peek();

bool isEmpty();

unsigned int getSize();

unsigned int getMaxCapacity();

T* getData();

private:

static double scale_factor;

int current_size;

int capacity;

T *STACK;

  

};

template <class T>

void ABS<T>::push( T data) {

std::cout << "In PUSH Operation" << std::endl;

if(current_size==capacity)

{

T * temp=new T [capacity*(int)scale_factor];

capacity=capacity*scale_factor;

for(int i=0; i<current_size; i++)

{

temp[i]=STACK[i];

STACK=temp;

}

STACK[current_size++]=data;

}

}

template <class T>

T ABS<T>::pop() {

std::cout << "In POP Operation" << std::endl;

if ( !isEmpty() ) {

T data=STACK[current_size--];

return data;

}

cout<<("Empty Stack")<<endl;

return NULL;

}

template <class T>

const T& ABS<T>::peek() {

std::cout << "In topElement Operation" << std::endl;

if ( !isEmpty() ) {

return STACK[current_size-1];

}

}

template <class T>

bool ABS<T>::isEmpty() {

if (current_size ==0) {

return true;

}

else {

return false;

}

}

template <class T>

unsigned int ABS<T>::getSize()

{

return current_size;

}

template <class T>

unsigned int ABS<T>::getMaxCapacity()

{

return capacity;

}

template <class T>

T ABS<T>::* getData()

{

T * temp=new T [capacity];

for(int i=0; i<current_size; i++)

{

temp[i]=STACK[i];

STACK=temp;

}

return temp;

}

#endif

PLEASE GIVE THUMBS UP,