Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6993807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:48:41+00:00 2026-05-27T19:48:41+00:00

I’m working on one of the programming challenges in the book Starting Out With

  • 0

I’m working on one of the programming challenges in the book Starting Out With C++ Early Objects 7th Edition and one of the assignments asks to create a class which is derived from the STL string class. I’m posting the question for the purpose of understanding what I am allowed to do and how I am supposed to implement the solution so that no one offers more advanced suggestions.

— Question as it is written in the text —

Palindrome Testing

A Palindrome is a string that reads the same backward as forward. For example, the words mom, dad, madam, and radar are 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 a 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 caracter at the position k in the string.

— End —

My main question is how do I access the member variable which holds my string object if the class I am deriving Pstring from is a class I did not write and I do not know how it implements its members?

For example,

#include <string>
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 (iBegin < iEnd && is_palindrome)
    {
      if (*iBegin++ != *iEnd--)
        is_palindrome = false;
    }

    return is_palindrome;

    // But I think this is wrong because...
    // #1 The book did not discuss the keyword auto yet
    // #2 The book discussed when a class is derived from another class,
    //    how the members from super class will be accessible to the sub class.
    //    However, with this assignment, I don't see how to access the members.
  }
}

The reason I feel like I am doing this incorrectly is because the assignment mentions using subscript notation, however, I don’t understand how to use the subscript notation if I don’t know the name of the variable where the string is stored.

Any help would be greatly appreciated because the author does not provide the solutions unless I am an instructor which is pretty lame in my opinion. It probably has to do with the fact that this is an academic text.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:48:42+00:00Added an answer on May 27, 2026 at 7:48 pm

    You shouldn’t inherit from std::string, as it wasn’t designed for that, nor do you need to in order to find a palindrome.

    See this: Inheriting and overriding functions of a std::string?

    Palindrome solution (from this question: Check if a string is palindrome Linked from this: C++ Palindrome finder optimization)

    #include <algorithm>
    
    bool isPal(const string& testing) {
        return std::equal(testing.begin(), testing.begin() + testing.size() / 2, testing.rbegin());
    }
    

    That book’s quality seems questionable. Free functions (depending on who you ask) are almost always preferred over member functions, and especially preferred over inheritance.


    If you must use inheritance:

    class Pstring : public string
    {
        //...
    
        bool isPalindrome()
        {
          return std::equal(begin(), begin() + size() / 2, rbegin());
    
          // as a side-note, 'iterator' will refer to the inherited return type of begin()
          // Also, 'operator[](x)' will call the subscript operator
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.