Dictionary Problem
Problem Specification
I want to translate words between English and some other language.
Make a simple dictionary into which I can put English words and their foreign equivalents.
I want to be able to give it an English word and have it return the foreign word.
Naturally, I also want to give it the foreign word and have it return an English one.
Since the advertising industry is always hard at work trying to change the meanings of English words, itās necessary to allow translations to be replaced.
Rules:
- Dictionaries have a fixed maximum size - specified when they're built.
- Words are supplied to the dictionary as C character strings and returned as C character strings.
- I need to be able to find out the current size of the dictionary.
- Assume that each English word has one and only one equivalent in the foreign language. The reverse assumption ö that every foreign word has only one English equivalent ö may also be made.
- As a consequence of (d), it is illegal to add a translation for a word thatās already in the dictionary. (However, I can replace an existing translation.)
- You can search the dictionary by any method, ie the simplest method will do. (Next year in the data structures course, you will learn about efficient, fast methods for doing this!)
For those with no knowledge of any foreign language, here are some possible translation tables for testing. Any one will do!
|
English |
American |
|
you |
you all |
|
footpath |
sidewalk |
|
roadway |
pavement |
|
socialism |
communism |
|
greed |
economic policy |
|
gaol |
jail |
| English |
Chinese |
Japanese |
Bahasa Indonesia/Melayu |
|
I |
wo3 |
watukshi |
saya |
|
you |
ni3 |
anata |
kau |
|
here |
zhe4li |
koko-ni |
disini |
|
there |
na4li |
asoko-ni |
disana |
|
where |
na3li |
doko |
dimana |
|
one |
yi1 |
ichi |
satu |
|
two |
er4 |
ni |
dua |
© John Morris, 1998