Due Thursday, March 3, 11:59 P.M.
- Overview
- Assignment
- Hints
The purpose of this lab is to introduce you to processing character
(textual) data in Fortran. You will also gain further practice using
loops and branching statements.
Top
Write a Fortran program called paldet that
reads in lines from standard input and prints out all the palindromes
it finds. Your program should satisfy the following requirements:
Top
- Since this is the first time you've used the alternate form of the
READ statement to detect EOF, start by writing some code that
reads in each line of standard input and writes it out again until
EOF occurs.
- Now write some more code to go through each line of input and store
each word to a scratch variable using substring specifiers. You will
need to find a way to detect the start and end of each word in the line.
Print out the values you store in the scratch variable to check that
you have this working properly before continuing.
- Convert each word to all uppercase or lowercase so you won't have
to worry about capitalization in the next step. The book has code for
converting strings to uppercase; you may want to try converting everything
to lowercase to make sure you understand how this code works.
- Now write some more code using substring specifiers to determine
whether the word in your scratch variable reads the same way backward as
forward, and make the WRITE statement from step 2 conditional
on this criterion.
- Now create a character variable large enough to hold the required
number of palindromes with spaces between them. Instead of writing
out the palindromes as you detect them, add them to the end of this
character variable. Add a WRITE statement at the end of your
program to display this character variable.
- Finally, test your program some more by hand, and try your program
on the Linux online dictionary using the command
./paldet < /usr/share/dict/words
You may also want to try your code on FreeBSD's version
of the online dictionary (FreeBSD is another freely available
implementation of UNIX). As usual, you will want to compare your results
with the output of my code and make sure they are consistent. You may
notice that your output automatically gets broken into lines 80 characters
in length, which causes some words to be split over multiple lines.
However, you don't need to worry about output formatting for this lab.
- Go back and clean up any extraneous output statements so that only the
list of palindromes is printed at the end.
Top
Back to the course information page