Where do I begin?

This is the first time Im working with inputting strings for analysis.

My program must check for palindrome words.

As the code is now. I get Error: no matching fuction for call to 'isPalindrome::Word(std::string&)'

My main

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include "isPalindrome.h"

using namespace std;

int main()
{
    isPalindrome word;
    std::string CheckWord;
    cout << "To verify a palindrome word, Input your word :" ;
    cin >> CheckWord;
    cout << word.Word(CheckWord);
    return 0;

    /*------------------------------------------------------------------------------------
    ======================================================================================
    ======================================================================================
    isPalindrome
A palindrome is a word that reads the same forwards and backwards; For
    example “noon” or “racecar”. Write a function isPalindrome which takes an array of
    characters and the length of that array; returning true if the characters form a valid
    palindrome and false otherwise.

    Your main program will use this function to test the following possible palindromes:

    “racecar”, “step on no pets”, “devil lived”, “elephant”, “nothing”
and for each one
    output it and then say whether it is a palindrome or not.
============================================================================================
============================================================================================
------------------------------------------------------------------------------------------*/

}


My .h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#ifndef ISPALINDROME_H
#define ISPALINDROME_H


class isPalindrome
{
    public:
        isPalindrome();
        isPalindrome(std::string);
        std::string Word();
        virtual ~isPalindrome();
    protected:
    private:
        char CheckingArray();

};

#endif // ISPALINDROME_H 


My .cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "isPalindrome.h"

isPalindrome::isPalindrome()
{
    //ctor
}


/*Edited********************************************************
                        Should this work for a start?
**************************************************************/
std::string isPalindrome::Word()
{
std::string word;
int countLetters = 0;
char letter;
while (letter!= '0'){
    letter = word[countLetters];
    countLetters++;
}
}

/*Edited*******************************************************/

isPalindrome::~isPalindrome()
{
    //dtor
}
Last edited on
In your .h file, you have
std::string Word();
but then in your .cpp file, you have
std::string isPalindrome::Word(std::string InputWord).
I'm not an expert so take this lightly.

You'll want to create an array for characters to store the palindrome and copy it to another array.

char word[10];
char isPalindrone[10];

cin >> word;

int count = 9;
for ( int x = 0; x < 10; x++ )
{
isPalindrone[count] = word[x]
count--; }

Now, to check if the reverse is the same as the original word.

for ( int x = 0; x < 10; x++ )
{ isPalindrone[x] == word[x]; }

From there you'll create a bool function to return TRUE if it is indeed a perfect match, or false if it is not. Be sure to initialize both arrays to a unused character such as '@' or something.


Hi,

Some points to help you out:

Don't have using namespace std; did I mention this in another post?

You have a constructor isPalindrome(std::string) , make use of it - get your input first then create the object with it.

Should you name the class Palindrome and have a function isPalindrome that returns a bool type?

You have the compiler error because your function definition & declaration don't match. But that might be negated by my previous sentence.

If you have compiler errors, then always post them in full and make sure the line numbers match so we can see what is going on.

To check that something is a palindrome, compare the first & last char - if they are equal then compare second & second to last, and so on until finished. Obviously if a comparison is false then it's not a palindrome. This is better than reversing a string, because that effort is wasted when it can be detected it is not a palindrome very early on.
How do I ask the program how many characters are in the string array?

should I have 2 functions taking the word simultaneously?

And yes You did tell me about (std::) but I wrote most of this code yesterday. I just posted it when I finished the code from the other post. I also have another thread going that needs attention. not as much as this one. and along the same line.

I appreciate you helping.
How do I ask the program how many characters are in the string array?


The std::string class has a bunch of member functions - look them up in the reference section at the top left of this page.

should I have 2 functions taking the word simultaneously?


Just use the constructor you have which takes a string as an argument, which should use that string to initialise a member variable via the initialisation list. Then have the IsPlaindrome function.

Hope all goes well.
Topic archived. No new replies allowed.