This lab involves:
Create a separate directory (lab04 is a good name) using mkdir for this week's lab exercises.
For example:
% a.out Enter string: Hello H e l l o
Write a program, palindrome.c, which reads a string and tests if it is a palindrome.
For example:
% a.out Enter possible palindrome: kayak String is a palindrome % a.out Enter possible palindrome: canoe String is not a palindrome
For example:
% a.out Enter possible palindrome: Do geese see God? String is a palindrome % a.out Enter possible palindrome: Do ducks see God? String is not a palindrome % a.out Enter possible palindrome: Madam, I'm Adam String is a palindrome % a.out Enter possible palindrome: Madam, I'm Bruce String is not a palindrome
Why might you want to do this? In the past, scholars of literature have actually used gross statistics of pieces of text, such as letter frequencies, to solve controversies over authorship.
The file data contains example input
for your program. Save it in your directory. Its contents are:
This is a little file of text. It's called "data". It has 6 lines of input. I'm going to use it for testing the letter count program I've just written.
When given data as input this is how your program should behave.
% a.out hello world <control-d> 1 lines of input read. 10 alphabetic characters read. 2 non-alphabetic characters read. The frequencies of the alphabetic characters was: 'd' 1 'e' 1 'h' 1 'l' 3 'o' 2 'r' 1 'w' 1 % a.out <data 6 lines of input read. 112 alphabetic characters read. 41 non-alphabetic characters read. The frequencies of the alphabetic characters was: 'a' 6 'c' 2 'd' 2 'e' 12 'f' 4 'g' 4 'h' 3 'i' 14 'j' 1 'l' 7 'm' 2 'n' 6 'o' 7 'p' 2 'r' 5 's' 8 't' 20 'u' 4 'v' 1 'w' 1 'x' 1
This output tells us that, for example, the letter 't' occurs 20
times in the text while the letter 'z' doesn't occur anywhere.
You should quickly check that the program has done the right thing, by hand counting some of the characters above in the text and making sure that your count agrees with what the program produced.
There are a couple of things to observe about the way this program
behaves.
First, it treats 't' and 'T' as being equivalent; there is a
'T' in the data file, but it has been counted towards the overall
count of 't's, if you check by hand.
Second, it counts in a separate category anything else that's not a letter of the alphabet, including digits.
Third, it doesn't print zero counts.
Finally, note very carefully the output format that the program uses; we want your program to produce its output in exactly the same format.
When you are sure all are working submit them using give. Here is the command to use:
% /home/cs1721/bin/classrun -give lab04 one.c palindrome.c frequency.c
This will run some simple tests.
Then get your tutor to check your answers are correct and give you the lab mark for this week.