Write a simple program in C++ that reads a line of text, changes each uppercase letter to lowercase, and places each letter both in a queue and onto a stack. The program should then verify whether the line of text is a palindrome (a set of letters or numbers that is the same whether read forward or backward). DO NOT USE THE STACK LIBRARY, QUEUE LIBRARY, OR ANY OTHER LIBRARIES NOT COVERED YET.
CODE:
#include<iostream>
#include<string>
#define MAX 100
using namespace std;
char S[MAX],Q[MAX];
int top=-1,front=-1,rear=-1;
void push(char ch) //function for
stack push operation
{
top=top+1;
S[top]=ch;
}
char
pop()
//function for stack pop operation
{
char ele;
if(top==-1)
return -1;
else
{
ele=S[top];
top=top-1;
return ele;
}
}
bool isEmpty() //function for checking stack is empty
or not
{
if(top==-1)
{
return true;
}
else
{
return false;
}
}
void enque(int x) //function for queue enqueue
operation
{
if(rear==MAX-1)
printf("QUEUE IS
OVERFLOWED:");
else
{
rear=rear+1;
Q[rear]=x;
if(rear==0)
front=0;
}
}
char deque() //function for queue dequeue
operation
{
char ele;
if(front==-1 || front>rear)
printf("QUEUE IS
UNDERFLOWED:");
else
{
ele=Q[front];
front=front+1;
return ele;
}
}
int main()
{
string text,text1;
int pal_length=0;
char stack_element,queue_element;
cout<<"Enter the text: ";
getline(cin,text);
text1=text;
for(int i=0;i<text.length();i++) //logic for
coverting string to lowercase
{
if(text[i]>='A' &&
text[i]<='Z')
{
text[i]=text[i]+32;
}
}
for(int i=0;i<text.length();i++)
{
push(text[i]);
//placing each character of a string in stack and queue
enque(text[i]);
}
while(!(isEmpty()))
{
stack_element=pop(); //popping element from
stack
queue_element=deque();
//dequeuing element from queue
if(stack_element==queue_element) //comparing
elements
{
pal_length=pal_length+1;
}
}
if(pal_length==text.length())
{
cout<<"The text
"<<text1<<" is a palindrome"<<endl;
}
else
{
cout<<"The text
"<<text1<<" is not a palindrome"<<endl;
}
}
OUTPUT:


Write a simple program in C++ that reads a line of text, changes each uppercase letter to lowerca...
Write a program that reads a line of text, changes each uppercase letter to lowercase, and places each letter both in a queue and onto a stack. The program should then verify whether the line of text is a palindrome (a set of letters or numbers that is the same whether read forward or backward). please use c++ language and use own queue class or class provided. plese do not use queue library. please use functions.
Palindrome Detector C++ A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here are some well-known palindromes: Able was I, ere I saw Elba A man, a plan, a canal, Panama Desserts, I stressed Kayak Write a program that determine whether an input string is a palindrome or not. Input: The program should prompt the user "Please enter a string to test for palindrome or type QUIT to exit: " and then wait for...
A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here are some well-known palindromes: Able was I, ere I saw Elba A man, a plan, a canal, Panama Desserts, I stressed Kayak Write a program that determine whether an input string is a palindrome or not. Input: The program should prompt the user "Please enter a string to test for palindrome or type QUIT to exit: " and then wait for the user input....
This is a java question A palindrome is a word or phrase that reads the same forward and backward, ignoring blanks and punctuations, and considering uppercase and lowercase versions of the same letter to be equal. For example, the following are palindromes: warts n straw radar Able was I ere I saw Elba tacocat Write a program named Palindrome.java that will accept a file (file name) from the command argument list and decide whether each line in the file is...
Develop a C++ program that reads a paragraph of text from a file. Tokenizes it such that each token is a word, determines whether a token is a palindrome (that is a word that reads the same forward and backward such as ‘madam’ or ‘1991’). Prints all palindrome and the total number of palindrome.Your source code shall consists at least three function apart from main(). Shows a program structure chart,flowchart,source code & output.
Need help in C
(a) Write a C program to read in a line of text and count the occurrence of each English alphabet. The lowercase version of a letter is considered the same as the uppercase. To make viewing easy, the frequencies should be presented using a bar chart as follows. You can assume that the input contains only spaces, lowercase letters, uppercase letters and the newline character (i.e. the Enter key). Enter a line of text: Letter ZZz...
A palindrome is a word or phrase that reads the same forward and backward, ignoring blanks and considering uppercase and lowercase versions of the same letter to be equal. For example, the following are palindromes: • warts n straw • radar • Able was I ere I saw Elba • tacocat Write a program that will accept a sequence of characters terminated by a period and will decide whether the string—without the period—is a palindrome. You may assume that the...
Question 2 Write a program that will read in a line of text up to 100 characters as string, and output the number of words in the line and the number of occurrences of each letter. Define a word to be any string of letters that is delimited at each end by whitespace, a period, a comma, or the beginning or end of the line. You can assume that the input consists entirely of letters, whitespace, commas, an<d periods. When...
JAVA Code: Complete the program that reads from a text file and counts the occurrence of each letter of the English alphabet. The given code already opens a specified text file and reads in the text one line at a time to a temporary String. Your task is to go through that String and count the occurrence of the letters and then print out the final tally of each letter (i.e., how many 'a's?, how many 'b's?, etc.) You can...
With basic (do not use #include <algorithm>, etc.) and simple C++ Write a program which reads a text file “input.txt” and stores all the distinct words in an array. A word consists of letters only - uppercase and/or lowercase. An incoming word should be inserted into the array such that it is always in ascending order. Use binary search to ensure that no duplicate words are added. Assume that there are no more than 100 distinct words. Assume that the...