i think im missing something could use a pointer heres the problem
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.
not looking for the answer just a push in the right direction heres the code I do have.
main.cpp
#include <iostream>
#include "Pstring.h"
using namespace std;
int main(int argc, char * const argv[]){
string test;
cout << "Enter word to test: ";
cin >> test;
Pstring palindromeTest(test);
return 0;
}
Pstring.cpp
#include "Pstring.h"
Pstring::Pstring() {
// TODO Auto-generated constructor stub
}
Pstring::~Pstring() {
// TODO Auto-generated destructor stub
}
Pstring::Pstring(string word){
static string testWord = word;
if (isPalindrome() == true) {
cout << "the word is a palindrome";
} else if (isPalindrome() == false) {
cout << "the word is not a palindrome";
}
}
bool Pstring::isPalindrome(){
int i,j;
string tempString = testWord;
for (i = 0, j = tempString.length(); i <= j; i++, j--) {
cerr<<testWord[i];
cerr<<tempString[j];
if (testWord[i] != tempString[j]) {
return false;
}
}
return true;
}
and the .h
#ifndef PSTRING_H_
#define PSTRING_H_
#include <iostream>
#include <string>
using namespace std;
class Pstring : public string {
public:
Pstring();
Pstring(string word);
virtual ~Pstring();
bool isPalindrome();
private:
string testWord;
};
#endif /* PSTRING_H_ */
thanks for any help