in c Write a program that allows you to read in an EnglishFr

in c++

Write a program that allows you to read in an English-French dictionary into an array of structures. The structures should hold an english word and it\'s french equivalent one. The dictionary data is stored in a file, call it dict.dat. sort the array of structures by the English word. Your revised program should then allow a user to look up an english word and then print it\'s french equivalent . Your dictionary should be able to store a maximum of 50 English and french words.

i\'m not particularly worried about the file in part, but if you need an example for testing an example of dict.dat could be: house maison mother mere father pere sister soeur brother frere library bibliotheque door porte hello bonjour good-bye au revoir cat chat dog chien book livre

What i\'ve come up with so far is Struct dictionary { char french [30] char English [30] constant int max =50 dictionary dictionary words [12] = {\"maison\" \"house\"} for the sort I was considering something like { for(int i = 0; i < used; i++) { for(int j = (i + 1); j < used; j++) { if(e[j] < e[i]) { string temp = e[j]; e[j] = e[i]; e[i] = temp; temp = f[j]; f[j] = f[i]; f[i] = temp; but i\'m not quite sure how it fits in an array of structures. Or structures in general. Any kind of help is appreciated, even if it\'s not a full answer.

Solution

I think your problem can be solved by using tries. Tries are data structures that store one alphabet per node, the child node will have the next alphabet. let\'s say you want to store two words \'bat\', \'ball\' etc. you store them like this:

B

|

A

| \\

T L

\\

L

Remember, each one of them is a node just like linked list node or tree node, this time its called a \'trie\' node. Typically each node contains a boolean \'isLeaf\' denoting if its a leaf node (thereby telling you that its a complete word), for example in above, T and L are leaf nodes, so in their case node.isLeaf will be true.

In your case instead of using isLeaf, you can simply say \'french\', so if node.french != null, there is a french equivalent word which you can print.

What you can try is:

1) read through the english french word pairs and write them to a file in the same way (it doesnt matter how you store it since we are anyway going to load everything into a trie structure)

2) read the entire file at the start of the program adding each word to the trie along with french equivalent

3) perform a trie lookup whenever you need to.

The time complexity of the whole thing should be O(n) (for the whole storing and retrieving from file) + O(word_length), word_length being the length of the word you want a lookup.

in c++ Write a program that allows you to read in an English-French dictionary into an array of structures. The structures should hold an english word and it\'s

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site