INPUT:

The program must read a series of lines of text from standard input.

The program must be able to input any series of lines of text -- no matter how long the lines happen to be and no matter how many lines there are. (That includes blank lines and the case where there are no lines at all in the series.)

OUTPUT:

The program writes one line of output for each line of input. The line of output corresponding to a given line of input consists of three items printed one after the other:

  • The characters of the input line,
  • A single hyphen, and
  • the characters of the input line in reverse order.

For example, if one of the lines of input is:

Hi There!

the corresponding line of output will be:

Hi There!-!erehT iH

The output lines are palindromes. A palindrome is a series of characters that reads the same backwards or forwards.

PROCESSING:

One of the goals of this assignment is to give you practice using recursion. Therefore you are required to solve this problem using recursion.

I want you to write a recursive function that inputs exactly one line of text from standard input and writes to standard output the corresponding palindrome. (The 'corresponding palindrome' is described above under 'OUTPUT.')

I want you to write the main function of the program to run a loop that calls the recursive function while EOF has not been reached.

The program should have only the two functions - the main function and the recursive helper function.

I advise you not to start writing code until you have thought of a very simple way for the recursive function to work. If you are thinking of a solution that is at all complicated, you are most probably on the wrong track.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.