Concepts: Pointers and pointer arrays
Write a program to read in a phrase from the keyboard, re-display the text, and display a message on the following line giving the text's status as a palindrome. Do not use any arrays or subscripting in this program, except for arrays of pointers.
A palindrome is a word or phrase which is the same backwards as
forwards; for example "civic", "toot", and "radar" are palindrome
words; each word is spelled the same left to right, as right to
left.
"A man, a plan, a canal - Panama!" is a palindrome phrase; ignoring
case, spaces and punctuation,
the phrase is spelled the same left to right, as right to left.
Determine if the phrase entered by the user is a palidrome. Setting a pointer to the first character in the entered text, and another pointer to the last character, move the pointers toward the center comparing the characters. Skip over anything that isn't a letter. If the pointers meet before finding any differences, you have a palindrome. Display a message to that effect on the next console line.
if you have any doubts, please give me comment...
#include<iostream>
#include<cctype>
#include<cstring>
using namespace std;
#define MAX_SIZE 100
int main(){
char *phrase = new char[MAX_SIZE];
cout<<"Enter phrase: ";
cin.getline(phrase, MAX_SIZE);
char *startPtr = phrase;
char *endPtr = phrase+strlen(phrase)-1;
bool isPalindrome = true;
while(startPtr<endPtr){
// cout<<*startPtr<<" "<<*endPtr<<endl;
if(ispunct(*startPtr) || isspace(*startPtr))
startPtr++;
else if(ispunct(*endPtr) || isspace(*endPtr))
endPtr--;
else if(toupper(*startPtr) != toupper(*endPtr)){
isPalindrome = false;
break;
}
else{
startPtr++;
endPtr--;
}
}
if(isPalindrome)
cout<<"Entered phrase "<<phrase<<" is a palindrome"<<endl;
else
cout<<"Entered phrase "<<phrase<<" is NOT a palindrome"<<endl;
return 0;
}
Concepts: Pointers and pointer arrays Write a program to read in a phrase from the keyboard,...
1 of 1 15 points) Palindrome Detector. A palindrome is a phrase that reads the Pi same ronwards as it does backwards. For example, "a man, a plan, a canal, Panama is a palindrome. Write a program that uses a stack to check for palindromes in each line of a text file. Try your program on the example text file "palindromes txt".Your program should output the palindromes that it finds in the document. For example: FindPalindromes( palindromes.txt") will display "a...
2. Write a program that takes a word that a user enters into a textbox, and displays the word reversed in an output text box. If the word is a palindrome (if the reversed word is the same as the initial word like mom, dad, anna), have a message box appear saying the word entered is a palindrome. You may use either a pretest or posttest do loop. Change werd ChangeWord Word apple Word: hannah Flp Word Backwards Result elppa...
Write a function palcheck (char word II) which takes a C-style string word (or a C++ string word if you wish) and returns or false depending on whether or not the string is a palindrome. (A palindrome is a string which reads the same backwards and forwards. Some classic example of palindromes are radar, racecar, toot, deed, bib, civic, redder and madam.) Use your function from part (a) in a complete C++ program which, for each small letter 'a' through...
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...
Write a program that reads each word from A1.txt and check if it's a palindrome or not. Show your output in the file Bl.txt. The total number of words in the file can change. You must use c-string or character arrays. Using String datatype and strrev() function are not allowed in this problem. "A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward." (Wikipedia) Sample Input: series madam Sample Output: yes
I need help programming this program in C. 1.) Write a program that reads a message, then checks whether it's a palindrome (the letters in the message are the same from left to right as from right to left), example is shown below: Enter a message: He lived as a devil, eh? Palindrome Enter a message: Madam, I am Adam. Not a Palindrome 2.) Ignore all characters that aren't letters. Use integer variables to keep track of positions in the...
Your program must prompt the user to enter a string. The program must then test the string entered by the user to determine whether it is a palindrome. A palindrome is a string that reads the same backwards and forwards, such as "radar", "racecar", and "able was I ere I saw elba". It is customary to ignore spaces, punctuation, and capitalization when looking for palindromes. For example, "A man, a plan, a canal. Panama!" is considered to be a palindrome....
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....
Problem #1 Create a program that performs the following functions: Uses character arrays to read a user's name from standard input Tells the user how many characters are in her name Displays the user's name in uppercase Create a program that uses the strstr() function to search the string "When the going gets tough, the tough stay put! for the following occurrences (display each occurrence found to standard output): "Going" "tou" "ay put!" Build a program that uses an array...