Sunday, April 29, 2007

 

Practise string handling with real text

As you practise handling strings in Turing, it's more fun to use "real" text. One great source of full-length books in ASCII format is www.gutenberg.org.
Now that you know how to access external files with your programs (Ch. 10), you can write programs to analyze a famous book and calculate what percentage is vowels, find the average length of a sentence, find the longest word, encrypt the text by replacing characters - all kinds of interesting things.

(Amaze your English teacher by announcing you know the exact number of times the words "love" and "hate" appear in Romeo and Juliet. Yowzah! Replace every other word in the whole book with your name and see if it is still readable. Change all the i's to 1s, the b's to 6s, the e's to 3s, the s's to 5s. Go crazy.)

Remember that the text should not contain any quotation marks, since Turing will interpret them as signs for tokens. Before you use the text, do a quick Search and Replace in Notepad to replace all the quotation marks (") with apostrophes (').



<< Home

This page is powered by Blogger. Isn't yours?