(Latest Revision: 03/09/2009)
Recursion: A Program That Makes Palindromes From Lines of
Text
PRELIMINARIES:
You need to read chapter two of Carrano before you begin this
assignment. You also need to read the directions and examples
here:
http://www.cs.csustan.edu/~john/Classes/General_Info/progAsgRules/
THE ASSIGNMENT:
Take a look at
this script
of me running a program.
Your assignment is to write a program that works like the
program illustrated by the script.
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.
HELP AND HINTS:
The problem of writing the recursive function to make a palindromes is
very similar to a problem that Carrano discusses in chapter two of our
textbook, and so be sure to read at least the first half of that
chapter before beginning this assignment.
We can discuss details of the assignment in class.
WHAT TO TURN IN:
You will turn in one printer output (hardcopy) and you will send me
two e-mail messages. Please follow these rules:
- Always send me e-mail as plain text in the main message
body. Never send me attachments.
- Always use the exact subject line I specify for
each message. (I often get hundreds of e-mail messages in a
week. The subject line allows me to find, filter and sort
messages.) You will lose a significant number of points on the
assignment if you use the wrong subject line.
- Be very careful when you send the e-mail. You may use the
instructions in your
Hello World! lab excercise
for guidance. Of course, you will need to make the obvious
changes to those directions -- you have to use the correct
subject line and filename.
- Always send yourself a copy of each e-mail message you
send to me, and check immediately to see if you receive
the message intact. You are responsible
for sending e-mail correctly.
Here is the list of things you have to turn in:
- On the
due date;
- At the start of class place a hardcopy of a
final level source file
of your program on the "counter" in front of me.
- The sheets of the hardcopy must be burst and stapled.
- "Burst" means
it doesn't have a 'holy-half-inch' on either side, and
the individual 8-1/2" X 11" sheets are all separated
from one another.
- Make sure that all of the code and script content shows
on the paper.
- Make sure all content is plainly readable and properly
formatted.
- Make sure that none of your lines of code or script
wraps around to a second line.
- Using the subject line: CS2500Prog2.f send a
final level source file
of your program to me by e-mail (no later than 11:59 PM on
the due date).
.
- Using the subject line: CS2500Script2.f send a
final level test script
of your program to me by e-mail (no later than 11:59 PM on
the due date).
Note that there are no spaces in the subject lines given. It is
important that you do not insert any spaces. My e-mail address is:
john@ishi.csustan.edu.
DUE DATES:
For the due dates, see
the class schedule.