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

USE C++ Create a Stack class that can handle characters. It should be able to au

ID: 3872203 • Letter: U

Question

USE C++

Create a Stack class that can handle characters. It should be able to automatically resize (to a larger size only) when full, becoming 1.5 times larger than it was. The stack class must contain the standard public functionality of push(), pop(), empty(). The only additional public functionality allowed isa peek() or top() method, depending upon your design choice. Do not use any of the STL (including the vector type) in your Stack. Test your Stack class by writing a driver that can determine if a provided string is a palindrome. Note that the strings will contain spaces and punctuation and these are not part of the palindrome. There is an unknown number of strings in the file - each is on a single line. The output should appear on the screen and list the string (with the punctuation and spaces intact) followed by whether or not it is a palindrome as in: "Mom" is a palindrome. "Cat" is NOT a palindrome. "Madam, I'm Adam" is a palindrome.

Explanation / Answer

#include <iostream>

using namespace std;

class stack

{

char a[1000];

int n;

public: stack()

{

n=0;

}

public: void push(char m)

{

a[n] = m;

n++;

}

public: void pop()

{

n--;

}

public: bool empty()

{

return (n==0);

}

public: char peek()

{

return a[n-1];

}

};

int main()

{

string s;

cout<<"Enter a string: ";

cin>>s;

stack st;

int n = s.length();

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

{

st.push(s.at(i));

}

int hat=0;

for(int i=n-1,j=0;i>=0;j++,i--)

{

if(st.peek()!=s.at(j))

{

hat=1;

break;

}

st.pop();

}

if(hat==1)

{

cout<<"""<<s<<"" "<<"is not a palindrome"<<endl;

}

else

{

cout<<"""<<s<<"" "<<"is a palindrome"<<endl;

}

return 0;

}