Question: C++ Write a program that uses a loop to keep asking the user for a sentence, and for each sentence tells the user if it

C++ Write a program that uses a loop to keep asking the user for a sentence, and for each sentence tells the user if it is a palindrome or not. The program should keep looping until the user types in END. After that, the program should display a count of how many sentences were typed in and how many palindromes were found. It should then quit.

Your program must have (and use) at least four VALUE RETURNING functions. Start out by writing your own reverse, uppercase and filter functions. You should write:

A reverse function that takes a string and returns it in reverse order.

This is a test 123! !321 tset a si sihT

An uppercase function that takes a string and returns it all uppercase.

This is a test 123! THIS IS A TEST 123!

A filter function that filters a string by returning only the letters and numbers of the string. (

This is a test 123! Thisisatest123

Then write a boolean function that uses the above functions to see if the given string is a palindrome.

I have my reverse, uppercase, and filter function written. It is returning as null. I believe something is wrong with my uppercase function and I am not sure how to write the boolean function. Also I am confused about what exactly to put into my main function.

Here is my code:

#include #include #include using namespace std;

string reverse(string s){ string result = ""; for(int i = s.length()-1; i>=0; i--){ //loop through each charcter of the string individually result += s[i]; } return result; }

string uppercase(string s){ for(int i = s.length(); i>=0; i++){ s[i] = toupper(s[i]); } return 0; }

string filter(string s){ string r = ""; // nothing between quotes int i = 0; while (i < s.length()){ char c = s[i]; if (isalnum(c)) // alphabet or number r += c; i++; } return r; }

int main(){ string s; cout << "Enter a string: "; getline(cin,s); cout << reverse(s) << uppercase(s) << filter(s); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!