Write an interactive program which maintains a German-English dictionary. The di
ID: 3740271 • Letter: W
Question
Write an interactive program which maintains a German-English dictionary. The dictionary will be implemented as a linked list with nodes in alphabetical order by German term. The user of the program should be able to carry out any of the following transactions: 1) add a German term and its English translation 2) delete a German term and its translation 3) change the English translation for a German term 4) query the English translation of a German term 5) display all of the German terms (and their translations) 6) quit the program The program should begin by reading a file containing the current contents of the dictionary, which would normally be created during previous runs of the program -- in our case it will be an initial file given to you to simulate previous runs of the program. Build a linked list with the German terms linked together in alphabetical order. Each German term/English translation should appear only once in the list. Each node in the list will contain a pointer to the next German term. When writing a real dictionary program, you would write the contents of the list to a file whenever the user chooses to terminate the program so that the current list could be restored next time the program is run, but you don’t have to implement this. Just print the dictionary before ending the program. In order to simplify searching for terms, all terms should be entered and stored in lower case. All searches for terms will check for an exact copy of whatever is stored. You would probably want a realistic program to be case insensitive and to be able to pick out a particular word from a series of words in a phrase, or to allow for reasonable misspellings by offering one or more choices which are spelled very similarly to the requested term. However, all this would complicate the comparisons enormously and would not add to your knowledge of linked lists, so we’ll keep things as simple as possible. Input: Current contents of dictionary (supposedly from previous runs of the program): file GERMAN.TXT Format: (records are pairs of lines in alphabetical German term order) Line 1 German term (one or more words, all in lower case) Line 2 English translation (one or more words, all in lower case) Requirements: 1) The dictionary must be implemented as a dynamically allocated linked list rather than an array- or vector-based list. 2) You (as the client) must handle the pointer manipulations by yourself rather than using a pre-defined list class (unless you want to create your own list class). 3) The list should be maintained in alphabetical order by German term. Here are some extra German terms and their English translations that you can use to test additions to your list: German: English translation: buch book verboten forbidden sprechen speak auf wiedersehen goodbye bruder brother klein small weil because jeder every kreuzweg crossroad alles everything
German.txt
Explanation / Answer
# encoding: utf-8
require 'nokogiri'
require 'open-uri'
require 'json'
mode=ARGV[0]
dictionaryHTML = Nokogiri::HTML(
open("h/3212-h.htm")
)
dictionaryObject={}
dictionaryHTML.xpath('//tr').each do |row|
if row.children.size() == 2 then
german = row.children[0].content
english = row.children[1].content
if mode=="ge" then
dictionaryObject[german]=english
elsif mode=="eg" then
dictionaryObject[english]=german
end
end
end
dictionaryJSON = JSON.generate(dictionaryObject)
puts dictionaryJSON
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.