Problem Directory: /home/bvanderz/cs140/Labs/palindrome
Problem Description
Write a recursive
function named
palindrome that
determines if a string is a palindrome, that is, it is equal to its reverse.
For example, "racecar", "g", and "tattarrattat" are palindromes.
The function should return a
bool with true indicating that the designated portion of the string is
a palindrome and false otherwise.
Parameters(string s, int begin, int end)
- s: the string being tested to determine if it is a palindrome
- begin: the index of the first character in the string where we should
start the testing.
- end: the index of the last character in the string where we should
end the testing.
As an example, palindrome("racecar", 1, 5) would return true
if "aceca" is a palindrome, since testing should start at index 1 and
end at index 5.
Constraints:
- The string is guaranteed to contain at least one character
- Any one character string is a palindrome
- Any function call in which begin is greater than end should return
true
- The arguments to the initial call to palindrome will be the string,
a beginning index of 0, and an ending index that points to the last
character of the string. For example, a call to palindrome with
"racecar" might be:
palindrome("racecar", 0, 6)
Subsequent recursive calls to palindrome may choose to increment/decrement
the beginning and ending indices.
Test Input: The input consists of a single word. For example:
racecar palindrome should return true
smiley palindrome should return false
tattarrattat palindrome should return true
brad palindrome should return false
What To Do
- You will modify the file named palindrome.cpp. Put your function
definition where the comment tells you to do so.
- Compile your file into an executable named "palindrome".
- There is an input file named input1.txt.
You can test your program by using this file as input to your program.
- There is an executable named "solution" that you can use to see
the correct output. An example execution would be:
./solution < input1.txt
- You can run the "gradeall" script to see if your program passes
the test cases.
- Get a TA to check you off when your function correctly passes the
test cases.