In C++, write a stack-based application, assignment7.cpp, which can be used to recognize palindromes (strings spelled identically both backward and forwards). Your program should ignore spaces and punctuation, as well as alpha cases; so, for instance, the string “Madam I’m Adam” counts as a palindrome. You must supply your own push and pop operations. For this exercise (alone) you can use global variables for the stack and the stack pointer. Be sure that your program does not let the user push more than 25 characters. Please add comments.
#include <iostream>
#include <string>
#include <stack>
#include <cctype>
using namespace std;
bool is_palindrome(string line) {
stack<char> s;
char ch;
string modified;
for (int i = 0; i < line.size(); ++i) {
ch = line[i];
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
modified += (char)tolower(ch);
s.push((char)tolower(ch));
}
}
for (int i = 0; i < modified.size(); ++i) {
if (modified[i] != s.top()) {
return false;
}
s.pop();
}
return true;
}
int main() {
string line;
cout << "Enter a sentence: ";
getline(cin, line);
if (is_palindrome(line)) {
cout << line << " is a palindrome" << endl;
} else {
cout << line << " is NOT a palindrome" << endl;
}
return 0;
}
In C++, write a stack-based application, assignment7.cpp, which can be used to recognize palindromes (strings spelled...
Using C language Palindromes A palindrome is a word or phrase that reads the same backwards and forwards, ignoring punctuation, spaces, and anything that isn’t a letter. Examples of Palindromes Madam, I’m Adam. Kayak Racecar A man, a plan, a canal – Panama! Able was I, ere I saw Elba. Go hang a salami, I’m a lasagna hog! Write a program that does the following: opens a text file named “Proj3input.txt” containing multiple lines of text (1 or more) for...
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...
#19
with the following instructions
19. A palindrome is a string that can be read backward and forward with the same result. For example, the following is a palindrome: Able was I ere I saw Elba. unction to test if a string is a palindrome using a stack. You can push characters in the stack one by one. When you reach the en string, you can pop the characters and form a new string. If the two strings are exactly...
Write a python program that contains a hardcoded string and checks whether it is a palindrome (the same forwards as backwards). If it is then display “It is a palindrome”, otherwise display “It is not a palindrome”. A hardcoded string is simply a string defined in your program, for example: my_string = “Hello” Some sample palindromes to use are: A car, a man, a maraca Desserts, I stressed Madam, I’m Adam You will need to strip out any punctuation such...
C Program: 6.31 (Palindromes) A palindrome is a string that's spelled the same way forward and backward. Some examples of palindromes are: "radar" "able was i ere i saw elba" and, if you ignore blanks: "a man a plan a canal panama" Write a recursive function testPalindrome that returns 1 if the string stored in the array is a palindrome and 0 otherwise. The function should ignore spaces and punctuation in the string. Use the function in a complete program...
Stack help. I need help with my lab assignment. Complete a method for a class named Palindrome that evaluates a string phrase to determine if the phrase is a palindrome or not. A palindrome is a sequence of characters that reads the same both forward and backward. When comparing the phrase to the same phrase with the characters in reverse order, an uppercase character is considered equivalent to the same character in lowercase, and spaces and punctuation are ignored. The...
I really need help with the code for this, in C++ please, I know there's a similar question but the answer isn't correct :[ A palindrome is a string that reads the same forwards and backwards (ignoring spaces, punctuation, and capitalization). Examples are the familiar ``If I had a hi-fi,'' the grander ``A man, a plan, a canal, Panama,'' and ``Some men interpret nine memos.'' So the goal: Design, implement, document, and test a program that reads a line of...
Overview: file you have to complete is
WordTree.h, WordTree.cpp, main.cpp
Write a program in C++ that reads an input text
file and counts the occurrence of individual words in the file. You
will see a binary tree to keep track of words and their counts.
Project description:
The program should open and read an input file (named
input.txt) in turn, and build a binary search tree
of the words and their counts. The words will be stored in
alphabetical order...