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

C++ The output of your program should like the below in red. Write a C++ program

ID: 3812447 • Letter: C

Question

C++

The output of your program should like the below in red.

Write a C++ program Palindrome.cpp that reads:

a- a line of text in lowercase,

b- placing each letter onto both a stack and a queue.

Verify whether the text is a palindrome. Remember to use the STL <stack> implementation of the stack in chapter5 and the STL <queue> implementation of the queue in chapter6.

Run1:
Enter a text in lowercase:
gohangasalamiimalasagnahog
Is a palindrome.

Run2:

Enter a text in lowercase:

abcdefghijklmopqrstuvwxyz

is not a palindrome

Explanation / Answer

#include<iostream>

#include<string>

#include<stack>

#include<queue>

using namespace std;

int main()

{

stack<char> s;

queue<char> q;

string str;

int i = 0;

char ch;

cout << "Enter a text in lowercase: ";

getline(cin, str);

cout << endl;

for (i=0; i<str.length(); i++)
{

ch = str[i];

q.push(ch); //compiler doesn't recognize enqueue so had to use push

s.push(ch);

}

while(!q.empty() && !s.empty())

{

if(q.front() != s.top())

{

cout << "The word " << str << " is not a palindrome" << endl;

break;

}

else if(q.front() = s.top())

{

i++;

q.pop(); //compiler doesn't recognize dequeue so had to use pop

s.pop();

if(i = str.length())

{

cout << "The word " << str << " is a palindrome" << endl;

break;

}

}

}

cin.get();

}

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