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)

  1. s: the string being tested to determine if it is a palindrome
  2. begin: the index of the first character in the string where we should start the testing.
  3. 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:

  1. The string is guaranteed to contain at least one character
  2. Any one character string is a palindrome
  3. Any function call in which begin is greater than end should return true
  4. 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

  1. You will modify the file named palindrome.cpp. Put your function definition where the comment tells you to do so.
  2. Compile your file into an executable named "palindrome".
  3. There is an input file named input1.txt. You can test your program by using this file as input to your program.
  4. There is an executable named "solution" that you can use to see the correct output. An example execution would be:
    	./solution < input1.txt
          
  5. You can run the "gradeall" script to see if your program passes the test cases.
  6. Get a TA to check you off when your function correctly passes the test cases.