Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

More Books

Students also viewed these Databases questions

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago