I'm working on an exercise with the intention on practicing vectors. The point of the exercise was to make a program that would check to see if a word entered is a palindrome.
Because I'm a beginner programmer, I'm wondering if there is any benefit to this code being over complicated. It doesn't need the vector, or to rebuild the word character by character. If one just uses the reverse function already in the code, that is enough right? I tested it by just using the reverse function and returning that value and it works great! Is there any sense to this, or am I over simplifying something and missing the point? I just can't see the use of the vector at all...
string makeritem(string item) {
string itemr = "";
vector<string> hold;
for(int i = 0; i < item.length(); ++i)
hold.push_back(item.substr(i,1));
reverse(item.begin(), item.end());
for(int i = 0; i < item.size(); ++i)
itemr += item[i];
return itemr;
}
int main()
{
string item, ritem;
cout << "Enter a word: ";
cin >> item;
ritem = makeritem(item);
if (ritem == item)
cout << "The word is a palindrome."
<< endl;
else
cout << "The word is not a palindrome."
<< endl;
return 0;
}