Question

Write a program that reads a line of text, changes each uppercase letter to lowercase, and places...

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.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

program in c++

#include <cctype>

#include <iostream>

#include <string>

#include <fstream>

using namespace std;

#define MAX 1000

class Stack

{

int top;

public:

string a[MAX]; //Maximum size of Stack

Stack() { top = -1; }

bool push(string x);

bool isEmpty();

string pop();

};

bool Stack::push(string x)

{

if (top >= (MAX-1))

{

cout << "Stack Overflow";

return false;

}

else

{

a[++top] = x;

cout<<x <<" pushed into stack\n";

return true;

}

}

string Stack::pop()

{

if (top < 0)

{

cout << "Stack Underflow";

return 0;

}

else

{

string x = a[top--];

return x;

}

}

class Queue {

private:

int i;

string arr_queue[MAX];

int rear;

int front;

public:

Queue() {

rear = 0;

front = 0;

}

void insert(string item) {

if (rear == MAX)

cout << "\n Queue Overloaded !";

else {

cout << item<<" Inserted into queue";

arr_queue[rear++] = item;

}

}

void display() {

cout << "\n## Queue Size : " << (rear - front);

for (i = front; i < rear; i++)

cout << "\nPosition : " << i << " , Value : " << arr_queue[i];

}

};

int main()

{

string line;// to hold line

std::ifstream file("input.txt");

std::string str;

class Stack s;

class Queue q;

while (std::getline(file, line))

{

cout<<"Read Line ::"<<line<<"\n";

for(int i = 0; i < line.length(); i++)

{

line[i] = tolower(line[i]);

}

s.push(line);

q.insert(line);

bool isPalindrome = true;

for(int i = 0; i < line.length(); i++)

{

isPalindrome *= line[i] == line[line.length() - 1 - i];

}

if(isPalindrome)

{

cout << "\n Line is a palindrome!" << endl << endl;

}

else

{

cout << "\n Line isn't a palindrome!" << endl << endl;

}

}

q.display();

cout<<"\n"<<s.pop() << " Popped from stack\n";


return 0;

}

/*

output

Read Line ::bhushan
bhushan pushed into stack
bhushan Inserted into queue
Line isn't a palindrome!

Read Line ::madam
madam pushed into stack
madam Inserted into queue
Line is a palindrome!

Read Line ::mahajan
mahajan pushed into stack
mahajan Inserted into queue
Line isn't a palindrome!


## Queue Size : 3
Position : 0 , Value : bhushan
Position : 1 , Value : madam
Position : 2 , Value : mahajan
mahajan Popped from stack

input.txt (file)

bhushan
madam
mahajan

*/

Add a comment
Know the answer?
Add Answer to:
Write a program that reads a line of text, changes each uppercase letter to lowercase, and places...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a simple program in C++ that reads a line of text, changes each uppercase letter to lowerca...

    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.

  • Palindrome Detector C++ A palindrome is any word, phrase, or sentence that reads the same forward...

    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...

    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...

    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...

  • Please Code in Java and follow the directions given Thanks Program required Directions .A palindrome is a str...

    Please Code in Java and follow the directions given Thanks Program required Directions .A palindrome is a string that reads the same forward and backward, i.e., the letters are the same whether you read them from right to left or from left to right. Examples: 3 a) radar à is a palindrome b)Able was I ere I saw Elba à is a palindrome e good à not a palindrome Write java program to read a line of text and tell...

  • A palindrome is a number or a text phrase that reads the same backward as forward....

    A palindrome is a number or a text phrase that reads the same backward as forward. For example, each of the following six-digit integers is a palindrome: 123321, 555555, 455554, and 116611. Write a pseudocode and C++ program that reads in a six-digit integer and determines whether or not it is a palindrome. You must use the division and remainder operators. Assume input is correct (six-digit integer). Please don't use loops. Do it with only using if else.

  • Develop a C++ program that reads a paragraph of text from a file. Tokenizes it such...

    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.

  • JAVA Code: Complete the program that reads from a text file and counts the occurrence of...

    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...

  • A palindrome is a word or phrase that reads the same forward and backward, ignoring blanks...

    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...

  • Need help in C (a) Write a C program to read in a line of text...

    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...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT