1

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

Question

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

C++ Programming

Palindrome Detector:

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 book function that uses recursion to determine if a string argument is a palindrome. The function should return true if the argument reads the same forward and backward. Demonstrate the function in a program, which continues to ask the user to type a text, and then print out the text is palindrome or not, until the user wants to quit the program. (Note: you might delete any punctuation signs firstly, only need to consider the letters)

(C++ Programming)

Answers

#include <iostream>

#include <cctype>

using namespace std;

//function declarations

bool testPalindrome(string str);

string upperCaseIt(string s);

int main()

{

//Declaring variables

string str,str1;

char ch;

  

/* This while loop continues to execute

* until the user enters other than 'y' or 'Y'

*/

while(true)

{

str1="";

//Getting the input entered by the user

cout<<"\nEnter a string :";

getline(cin,str);

  

//eliminating spaces,commas..etc

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

{

if(isalpha(str[i]))

str1+=str[i];

}

//calling the function

str1=upperCaseIt(str1);

//calling the function

if(testPalindrome(str1))

cout<<"This is a Palindrome"<<endl;

else

cout<<"This is not a Palindrome"<<endl;  

cout<<"\nDo you Want to continue(Y/N):";

cin>>ch;

if(ch=='y'||ch=='Y')

{

cin.ignore();

continue;

}else

{

break;

}

}

return 0;

}

/* This is a recursive function which calculates

* whether the String is Palindrome or not using recursive method

* Param:string

* return: boolean

*/

bool testPalindrome(string str) {

if(str.length() == 0 || str.length() == 1)

return true;

else if(str[0] == str[str.length()-1])

return testPalindrome(str.substr(1, str.length()-2));

  

return false;

}

// This function will convert the lower case to upper case

string upperCaseIt(string s)

{

for (int i = 0; i < s.size(); i++)

{

if (s.at(i) >= 97 && s.at(i) <= 122)

{

s.at(i) = s.at(i) - 32;

}

}

return s;

}

_____________________

Output:

ב c:\ CAProgram Files (x86) Dev-CpplMinGW641bin\PlaindromelrrespectiveOfSpacesCommaR Files Enter a string Able was I. ere I s

______________Thank You


Similar Solved Questions

1 answers
I. (5 points) Let X be a random variable with moment generating function M(t) = E...
I. (5 points) Let X be a random variable with moment generating function M(t) = E [etx]. For t > 0 and a 〉 0, prove that and consequently, P(X > a inf etaM(t). t>0 These bounds are known as Chernoff's bounds. (Hint: Define Z etX and use Markov inequality.)...
1 answers
Supply 17.) Refer to the graph shown. When the price falls from PI to P2, the...
Supply 17.) Refer to the graph shown. When the price falls from PI to P2, the producer surplus a. decreases by A. b. increases by B. c. is A+B. d.is A+B+C+D. e, both a and care correct. 18.) Refer to the graph above. When the market price of the good that you sell goes from P2 to P1, then: you incre...
1 answers
The following transactions pertain to Accounting Solutions Inc. Assume the transactions for the purchase of the...
The following transactions pertain to Accounting Solutions Inc. Assume the transactions for the purchase of the computer and any capital improvements occur on January 1 each year. Year 1 1. Acquired $63,000 cash from the issue of common stock. 2. Purchased a computer system for $22,700. It has an es...
1 answers
How were the mission, vision, and values similar to and different from your personal philosophy of...
How were the mission, vision, and values similar to and different from your personal philosophy of nursing and core values?...
1 answers
Shane does not like the idea Sharing the cost equally because he plans to stay in...
shane does not like the idea Sharing the cost equally because he plans to stay in the room rather than ski Shane suggest to each type of guys be allocated to each person based on the above listed allocation bases using the activity allocation for each person please calculate the amount that each per...
1 answers
Does 5+(11+8)=5+8+11. Illustrate the commutative the commutative or associative property? explain your answer
Does 5+(11+8)=5+8+11. Illustrate the commutative the commutative or associative property? explain your answer...
1 answers
A moving company purchased a van for $50,000. If the company shuts down now, it could...
A moving company purchased a van for $50,000. If the company shuts down now, it could sell the van for $30,000. The relevant cost of the van when considering whether or not to shut down is O $80,000 O $50,000 O $30,000 O $20,000...
1 answers
4 Please use python and opencv library in python to implement the following tasks. Given a...
4 Please use python and opencv library in python to implement the following tasks. Given a gray image 'test.jpg', first use Average filter to smooth it, then detect keypoints by using Harris corner detector, finally show the image with keypoints. (10.09)...
1 answers
QUESTION 1 What is the second stage of glucose oxidation in eukaryotes? The Citric Acid Cycle...
QUESTION 1 What is the second stage of glucose oxidation in eukaryotes? The Citric Acid Cycle A. B. Glycolysis C.Electron-Transport Chain D.ATP Synthesis...
1 answers
17. A company has beginning inventory of 15 units at a cost of $25 each on...
17. A company has beginning inventory of 15 units at a cost of $25 each on February 1 On February 3, it purchases 35 units at $27 each. 17 units are sold on February 5. Using the FIFO periodic inventory method, what is the cost of the 17 units that are sold?...
1 answers
Write a 250-word paragraph about the structure and function of this virus. This paragraph should address...
Write a 250-word paragraph about the structure and function of this virus. This paragraph should address the following questions: 1. What kinds of genomes can viruses have? 2. What kind of genetics does SARSCOV2 SPECIFICALLY have? 3. How does this determine the life cycle of the virus? For example, ...
1 answers
B) (12,5 point) Find the equation of the cone surface whose directrix is the ellipse {4.x2...
b) (12,5 point) Find the equation of the cone surface whose directrix is the ellipse {4.x2 + x2 = 1, y = 4} and whose vertex is the point V(1,1,3)....
1 answers
H H2C CH₃ 2. Draw the structure of the following compounds. a. 3-methyl-3 phenylbutanal H₂ b. 3-Oxobutanoic acid c....
H H2C CH₃ 2. Draw the structure of the following compounds. a. 3-methyl-3 phenylbutanal H₂ b. 3-Oxobutanoic acid c. 1,3-Cyclohexanedione 3. Show how you can synthesize the compound below by H3C H3C...

-- 0.046969--