(C++) A palindrome is a string that reads the same backward as forward. For exam
ID: 3645448 • Letter: #
Question
(C++) A palindrome is a string that reads the same backward as forward. For example, the words mom, dad, madam, and radar are all palindromes. Write a class Pstring that is derived from the STL string class. The Pstring class adds a member function "bool isPalindrome() that determines whether the string is a palindrome. Include a constructor that takes an STL string object as parameter and passes it to the string base class constructor. Test your class by having a main program that asks the user to enter a string. The program uses the string to initialize a Pstring object and then calls "isPalindrome()" to determine whether the string entered is a palindrome. You may find it useful to use the subscript operator [] of the string class: if str is a string object and k is an integer, then str[k] returns the character at position k in the string.Explanation / Answer
#include using namespace std; class Pstring : public string { public: Pstring(std::string text) : string(text) { } bool isPalindrome() { // How do I access the string if I am passing it to the base class? // What I think I should do is... bool is_palindrome = true; auto iBegin = begin(); auto iEnd = end() - 1; while (iBeginRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.