MindTap - Cengage Learning - Microsoft Edge A https://ng.cengage.com/static/nb/ui/evo/index.html?deploymentld=57811235846758605217306036&elSBN=9781337274715&id=710937854&snapshotld=1589550& >> CENGAGE MINDTAP Q Search this course Programming Exercise 6-1 Tasks main.cpp >_ Terminal 34 main.cpp: In function 'bool isPal indrome(std::_cxx11::string)': пain.cpp:18:17: еггог: еxреcted p rimary-expression before '!=' tok Code Pattern • Complete 35 //Prompt the user to enter the string Uses function `isPalindrome' cout <<"Enter the string: "; A-Z 36 37 //Get the input string en Code Pattern • Incomplete cin >> str; if (str[m]) != str[len - 1 - m]) 38 /3 Tested isPalindrome with the 39 "Madam" string argument //Iterate through the characters in a string 40 for_each (str.begin(), str.end (), [] (char & ch) { /bin/bash: line 4: ./a.out: No su ch file or directory 41 Description 42 Searched your code for a specific 43 //Convert the letter into lower-case pattern: 44 ch = ::tolower(ch); B); 45 .+*isPalindrome\(\"Madam\"\).+* 46 47 //Assign the value returned from the function call You can learn more about regular 48 bool s = isPalindrome(str); bongo expressions here. 49 50 //check if the value is true if (s == true) 51 Code Pattern • Incomplete 52 //Print the message Tested isPalindrome with the 53 cout <« str «" is a palindrome"; "abBa" string argument 54 55 //otherwise Description 56 else Searched your code for a specific pattern: 57 //Print the message 58 cout <« str «" is not a palindrome"; 59 return 0; Run Checks Submit 0% 7:57 PM P Type here to search Answered: Here are.. MindTap - Cengag.. 4/9/2020 MindTap - Cengage Learning - Microsoft Edge A https://ng.cengage.com/static/nb/ui/evo/index.html?deploymentld=57811235846758605217306036&elSBN=9781337274715&id=710937854&snapshotld=1589550& >> CENGAGE MINDTAP Q Search this course Programming Exercise 6-1 Tasks main.cpp >_ Terminal 33 string str; main.cpp: In function 'bool isPal indrome(std::_cxx11::string)': пain.cpp:18:17: еггог: еxреcted p rimary-expression before '!=' tok Code Pattern • Complete <> 34 Uses function `isPalindrome' A-Z 35 //Prompt the user to enter the string 36 cout <<"Enter the string: "; en Code Pattern • Incomplete //Get the input string cin >> str; if (str[m]) != str[len - 1 - m]) 37 /3 Tested isPalindrome with the 38 "Madam" string argument /bin/bash: line 4: ./a.out: No su ch file or directory 39 40 //Iterate through the characters in a string Description for_each (str.begin(), str.end (), [] (char & ch) { 41 Searched your code for a specific 42 pattern: 43 //Convert the letter into lower-case ch = ::tolower(ch); 44 .+*isPalindrome\(\"Madam\"\).+* 45 }); 46 You can learn more about regular bongo 47 //Assign the value returned from the function call expressions here. 48 bool s = isPalindrome(str); 49 Code Pattern • Incomplete 50 //check if the value is true if (s true) Tested isPalindrome with the 51 "abBa" string argument //Print the message 52 53 cout <« str «" is a palindrome"; Description 54 55 //otherwise Searched your code for a specific 56 else pattern: 57 //Print the message 58 cout <« str «" is not a palindrome"; Run Checks Submit 0% 8:11 PM P Type here to search Answered: Here are... MindTap - Cengag.. ProgrammingExerc. 4/9/2020
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?
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 4 images