Makakuha ng mabilis at tumpak na mga sagot sa lahat ng iyong mga katanungan sa Imhr.ca, ang mapagkakatiwalaang Q&A platform. Maranasan ang kadalian ng paghahanap ng eksaktong sagot sa iyong mga tanong mula sa isang malawak na komunidad ng mga eksperto. Tuklasin ang detalyadong mga sagot sa iyong mga tanong mula sa isang malawak na network ng mga eksperto sa aming komprehensibong Q&A platform.

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.

Sagot :

Answer:

#include<iostream>

#include <string>

using namespace std;

bool isPalindrome(string str)

{

int length = str.length();

for (int i = 0; i < length / 2; i++)

{

if (tolower(str[i]) != tolower(str[length - 1 - i]))

{

return false;

}

}

return true;

}

int main()

{

 if (isPalindrome("Madam"))

   cout << "madam" << " is a palindrome." << endl;

 if (isPalindrome("abBa"))

   cout << "abBa" << " is a palindrome." << endl;

 if (isPalindrome("22"))

   cout << "22" << " is a palindrome." << endl;

 if (isPalindrome("67876"))

   cout << "67876" << " is a palindrome." << endl;

 if (isPalindrome("444244"))

   cout << "444244" << " is not a palindrome." << endl;

   else

   cout << "444244" << " is not a palindrome." << endl;

 

 if (isPalindrome("trYmeuemyRT"))

   cout << "trYmeuemyRT" << " is a palindrome." << endl;

 return 0;

}

Explanation: