If you are a course participant, please send the solutions to these exercises to erikt(at)science.uva.nl before or on Tuesday September 25, 2007. Do not forget to test your programs. Include the test results in your weekly reports.
Write a program that reads numbers between zero and ninety-nine (inclusive; one per line) and prints the number in digits. The program should stop when the user presses Enter without entering anything else. Example run:
Please enter a number in characters: zero You have entered: 0 Please enter a number in characters: eleven You have entered: 11 Please enter a number in characters: ninety-nine You have entered: 99 Please enter a number in characters: Thanks for using this program!
[Solution] Only look at the solution when you have finished the exercise or when you are completely stuck.
Pig Latin is a variant of Latin in which each word is replaced by a variant. Two rules are used for creating the word variants:
Write a program which reads some lines of text until an empty line is read and then outputs the Pig Latin version of the text. The input may only consist of lower case characters (leave out capital characters and punctuation). Example:
Enter a text, line by line. Finish with an empty line. > this text will be difficult to read > once it is translated to pig latin > isthay exttay illway ebay ifficultday otay eadray onceay itay isay anslatedtray otay igpay atinlay
Make regular expressions for the following string descriptions:
You can test the expressions by putting them in a small program which tests whether an input string matches the expression or not.
Write a program that plays a letter game. It generates questions of the format: What is the 3rd letter following f? The user has to respond with the correct answer (in this case i). The program should choose arbitrary letters itself as well as the relative positions (1-10, either before or following the current letter). After ten questions, the program should stop and give an overview of the user's performance. Example:
1. What is the 3rd letter following f? > i Correct! 2. What is the 2nd letter before z? > y Wrong. ... You have 7 correct answers on 10 questions.
Write a program that reads the plural of a word (you are free to use either English or Dutch) and prints the singular form. The program should process plurals until the user presses Enter without entering a word. Example run:
Please enter a plural: boys The singular form is: boy Please enter a plural: dishes The singular form is: dish Please enter a plural: cherries The singular form is: cherry Please enter a plural: wolves The singular form is: wolf Please enter a plural: fish The singular form is: fish Please enter a plural: feet The singular form is: foot Please enter a plural: attorneys general The singular form is: attorney general Please enter a plural word: Thanks for using this program!
It is too much work to achieve 100% coverage but try to handle a reasonable number of cases. Test your program with plurals that are handled correctly as well as with some that the program cannot process well.