void mystery(string a, string &b)
{
a.erase(0, 1);
b += a[0];
b.insert(3, "FOO");
}
int main()
{
string a = "thomas";
string b = "edison";
mystery(a, b);
cout << a << " " << b << endl;
return 0;
}
Explain.
MALAYALAM is a palindrome, because the reverse of this string is also MALAYALAM. Similarly, madam and AbbA are palindromes.
Write a method checkPalindrome(string const &s) that takes a string parameter (s) and returns the boolean value TRUE if s is a palindrome; otherwise it returns FALSE. Also, write the main function similar to what is shown below to read user input repeatedly (until a sentinel value) and check if the input line is a palindrome or not.
bool checkPalindrome(string const &s)
{
//your code here
}
int main()
{
while (1) {
string line;
line = getLine("Enter next string to be checked: ");
if (line == "") {
break;
}
if (checkPalindrome(line)) {
cout << "Yes, " << line << " is a palindrome." << endl;
} else {
cout << "No, " << line << " is not a palindrome." << endl;
}
}
}
Test your program with multiple inputs. Also answer the following questions:
checkPalindrome() is a const parameter? Would it be okay to change this to pass-by-value? Would it be okay to change this to (non-const) pass-by-reference? What are the considerations which allow us to choose one over another?