Palindrome homework exercises c++ [closed]

I am not going to give you the answer, but I will give some hints.

The palindrome program is taking a string and comparing characters. More specifically, it is taking the first character, comparing it to the second-to-last, and seeing if they match. If they do, compare the second character to the third-to-last, and continue until all character pairs are examined, or if a non-matching pair is found, it will bail out.

Remember, strings in c++ are null terminated, so the last character is always the null character symbol. That is why we have to compare the n-th and n-th-1.

Deep down, a string is just a character array, that is, a collection of characters. Every character has an ASCII value, and every value corresponds to exactly one character. A is the decimal value of 65, B is the decimal value 66, a is the decimal value 97, b is the decimal value 98, and so on.

Google ASCII Table for some pictures, if this doesn’t make much sense, yet.

What your homework is saying is that the string “pop” is a palindrome, but “Pop” isn’t. This is clearly a bug in the program. You need to find a method to make the string all lower case, or all upper case in order to squish this bug.

Is there a method like str.ToUpper(), or str.ToLower()? If so, where do you want to add it, at the top, or bottom of your function? If not, can you do ASCII comparisons to find all upper or lower characters, and adjust them? Where would you want to do that?

(Hint: there is more than one way to solve this problem. Find one, and stick to it. I have given you three potential solutions in the above paragraph.)

On a final note, don’t give up so easily. If you have problems, please ask for help! It is common to feel confused and lost. Your professor is there to help you. Other professors are there to help. Ask them. Ask your classmates. Ask lots of questions. This stuff looks confusing and daunting. Please don’t let it scare you away.

Heck, I have been pretending to be a professional programmer for over a decade, and I still find myself googling and asking questions nearly daily.

Good luck!

Leave a Comment