Code of the following but incorrect attach sa. Not to remove any thing elaww.
Thanks for the help, but I'm not finished yet. Here are my instructions for my C++
Write a program that uses the
function isPalindrome given in
Example 6-6 (Palindrome). Test
your program on the following
strings:
madam, abba, 22, 67876, 444244, trymeuemyrt
Modify the function isPalindrome
of Example 6-6 so that when
determining whether a string is a
palindrome, cases are ignored, that
is, uppercase and lowercase letters
are considered the same.
The isPalindrome function from
Example 6-6 has been included
below for your convenience.
bool isPalindrome(string str)
{
int length = str.length();
for (int i = 0; i < length / 2; i++) {
if (str[i] != str[length – 1 – i]) {
return false;
} // if
} // for loop
return true;
}// isPalindrome
Your program should print a
message indicating if a string is a
palindrome:
madam is a palindrome
Here's what I have so far:
//Include the neccessary header files.
#include <iostream>
#include <string.h>
#include <algorithm>
//Declare the neccessary namespace statements.
using namespace std;
//Define the function
bool isPalindrome(string str)
{
//Compute the string length
int len = str.length();
//Iterate till the middle of the string
for (int m = 0; m < len / 2; m++)
{
//Check the condition
if (str[m]) != str[len - 1 - m])
{
//if for loop returns false
return false;
}
}
//if for loop returns true
return true;
}
//Define the main function
int main()
{
//Declare the variable
string str;
//Prompt the user to enter the string
cout <<"Enter the string: ";
//Get the input string
cin >> str;
//Iterate through the characters in a string
for_each (str.begin(), str.end(), [] (char & ch) {
//Convert the letter into lower-case
ch = ::tolower(ch);
});
//Assign the value returned from the function call
bool s = isPalindrome(str);
//Check if the value is true
if (s == true)
//Print the message
cout << str <<" is a palindrome";
//Otherwise
else
//Print the message
cout << str <<" is not a palindrome";
return 0;
}
As you can see from my screenshot I have 1 error in my program and my exercise is incomplete. According to the complier my only error is on line 18. So in need help fixing any sytax errors.
Also, according to the lab environment (see 6-1a.Capture.PNG), on line 48, the bool expression doesn't cover any of the string values. The lab values still require that I have the following string patterns in my lab:
.+*isPalindrome\(\"Madam\"\).+*
.+*isPalindrome\(\"abBa\"\).+*
.+*isPalindrome\(\"22\"\).+*
.+*isPalindrome\(\"67876\"\).+*
.+*isPalindrome\(\"444244\"\).+*
.+*isPalindrome\(\"trYmeuemyRT\"\).+*
Finally, the program doesn't display whether any of the string values are palindromes or not. Can anyone help?.... L
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 3 images
- Write a function which will swap its arguments if the first argument is greater than its second argument,but will not interchange them if the first argument is smaller than or equal to the second argument. Thefunction should return 1 if a swap was made, and 0 otherwise.(Hint: Make sure to use call by reference.)Write also a short test driver(i.e. a main() invoking your function). C++arrow_forwardCan someone help me fix and correct this C program .It fails to compile and run .Ive tried everything .It is supposed to come out exactly like the example output.I keep geting these error codes during compilation. ERRORS GIVEN DURING COMPILATION: In function ‘main’:cntwlc.c:20:2: error: parameter ‘num_lines’ is initialized int num_lines = 0, num_words = 0, num_chars = 0, num_alpha = 0, num_digits = 0, num_special = 0; ^cntwlc.c:20:2: error: parameter ‘num_words’ is initializedcntwlc.c:20:2: error: parameter ‘num_chars’ is initializedcntwlc.c:20:2: error: parameter ‘num_alpha’ is initializedcntwlc.c:20:2: error: parameter ‘num_digits’ is initializedcntwlc.c:20:2: error: parameter ‘num_special’ is initializedcntwlc.c:21:2: error: expected declaration specifiers before ‘printf’ printf("Welcome to cntwlc the CIS158 version of the word count.\n\n"); ^cntwlc.c:22:2: error: expected declaration specifiers before ‘printf’ printf("This program will produce statistics about the text…arrow_forwardI am working on a C++ workshop and having problem with this function. I use step in (F11) to debug line-by-line and find that my if statement if (ptr_rec->user_name == "\n") did not match "\n" after receiving pure "enter" input. How can I revise my code so that it I can "press Enter to exit" with my code structure? overload read function with problem - if statement (ptr_rec->user_name == "\n") not matching the condition // Requests to enter Customers record, return false if name is empty after enter bool read(Customers& rec) { bool check = true; ptr_rec = new Customers; cout << "Enter User name : "; read(ptr_rec->user_name, 12); if (ptr_rec->user_name == "\n") { check = false; } else { cout << "Enter likes_count: "; cin >> ptr_rec->likes_count; cout << "Enter retweets_count: "; cin >> ptr_rec->retweets_count; cout…arrow_forward
- USING C++ Please fix the errors in the code (image attached) with the failed test warning (image attached). Thank you! Write a program that removes all non-alphabetic characters from the given input. Ex: If the input is: -Hello, 1 world$! the output is: Helloworld Your program must define and call the following function that takes a string as a parameter and returns the string without any non-alphabetic characters.string RemoveNonAlpha(string userString)arrow_forwardplease code this for me in c++ using void, functions, loops, (basic c++ not complicated or highlevel please). I tried to code it myself but there are many mistakes I dont know how to fix so please write a similar one for me but it works. The question is only 1 but it has 2 parts (2 different functions that should be in one code) MY CODE: #include <iostream>using namespace std; int IsPalindrome(int p);void GCD(); int main (){ int choice; cout << "Please enter a choice: "<<endl; cout << "Enter one for IsPalindrome "<<endl; cout << "Enter 2 for GCD "<<endl; cout << "Enter 3 to exit the program "<<endl; cout << "Choice: "<<endl; cin >> choice; if (choice == 1) { int p; cout << "Please enter a 3 digit number: "<<endl; cin >> p; if(p%10==p/100) { cout<<p<<" is a palindrome " <<endl; } else {…arrow_forwardWrite a C++ program that will print out the following simple shapes: triangle, rectangle and diamond using different characters for each shape. Requirements:- each shape uses a different character and it must be exactly 5 lines.- for this exercise, please do not use loop but only simple printing characters.arrow_forward
- Here are my instructions for my C++ program: Write a program that uses thefunction isPalindrome given inExample 6-6 (Palindrome). Testyour program on the followingstrings:madam, abba, 22, 67876, 444244, trymeuemyrt Modify the function isPalindromeof Example 6-6 so that whendetermining whether a string is apalindrome, cases are ignored, thatis, uppercase and lowercase lettersare considered the same. The isPalindrome function fromExample 6-6 has been includedbelow for your convenience. bool isPalindrome(string str){int length = str.length();for (int i = 0; i < length / 2; i++) {if (str[i] != str[length – 1 – i]) {return false;} // if} // for loopreturn true;}// isPalindrome Your program should print amessage indicating if a string is apalindrome: madam is a palindrome The lab values require that I have the following string patterns in my lab: .+*isPalindrome\(\"Madam\"\).+* .+*isPalindrome\(\"abBa\"\).+* .+*isPalindrome\(\"22\"\).+* .+*isPalindrome\(\"67876\"\).+*…arrow_forwardThis assignment will give you practice on basic C programming. You will implement a few Cprogramsarrow_forwardCan someone help me to fix my user-defined, value-returning expression? Here's the instructions to my C++ Program: Instructions Write a value-returning function, isVowel, that returns the value true if a given character is a vowel and otherwise returns false. For the input E, your output should look like the following:E is a vowel: 1 When printing the value of a bool, true will be displayed as 1 and false will be displayed as 0. And here's what I have so far: //Declare include-header files#include <iostream> #include <string.h> //Declare namespace statementsusing namespace std; //Define the isVowel userdefined value-returning functionint isVowel(char ch){if ((ch == 'A') || (ch == "E") || (ch == 'I') || (ch == "O") || (ch == "U") || (ch == 'a') || (ch =='e') || (ch == 'i') || (ch == 'o') || (ch == 'u')) {return true;}else{return false;}}} int main() //Define the main function{//Define variableschar character; //Testing the isVowel function.//Prompt the user to input a…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education