Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using Hash Table C++ Starter: HashTable, dictionary.txt, document.txt and starte

ID: 3716749 • Letter: U

Question

Using Hash Table

C++

Starter:  HashTable, dictionary.txt, document.txt and starter.cpp

Provide a main program. Your main program should do the following:

(a) Create a hash table whose size is equal to the number of words in the dictionary.

(b) Read the words from the dictionary and store each one in the hash table.

(c) Output the statistics (i.e. minimum, maximum, and mean chain length) of the hash table after all words in the dictionary has been stored in the hash table.

(d) Read the words from the document and output each word that is NOT in the dictionary.

Here is the link of dictionary.txt, document.txt and starter.cpp

starter:https://hastebin.com/befuvoyaxu.cpp

Output should be like this:

Explanation / Answer

FILE: dictionary.txt

20
ape
apple
ali
bowl
bad
cotton
door
from
floor
from
good
hand
sonu
vivo
yellow
yard
zoo
ali
door
EOF

FILE: document.txt

door
hello
ape
god
hen

JAVA CODE:

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Hashtable;
import java.util.Scanner;
import java.util.Set;

public class HashTableMain {

public static void printStats(Hashtable<String, String> dictTable,
           int numberOfWords) {

       int min = dictTable.size();
       int max = numberOfWords;
       double mean = (min + max) / 2.f;
       System.out.println("minimum maximum mean");
       System.out.println(" "+min+" "+max+" "+mean);
   }

   @SuppressWarnings("resource")
   public static void main(String[] args) throws FileNotFoundException {

       int numberOfWords = 0;
       int count = 1;
       Hashtable<String, String> dictionaryTable = null;
       Hashtable<String, String> wordsNotFound = new Hashtable<String, String>();

       Scanner scan = new Scanner(new File("files/dictionary.txt"));
       if (scan.hasNextLine()) {
           numberOfWords = Integer.parseInt(scan.nextLine());
           dictionaryTable = new Hashtable<String, String>(numberOfWords);
       }
       while (scan.hasNextLine()) {
           String word = scan.nextLine();
           dictionaryTable.put(word, word);
       }

       //System.out.println(dictionaryTable);

       scan = new Scanner(new File("files/document.txt"));
       while (scan.hasNextLine()) {
           String docWord = scan.nextLine();

           String fromDic = dictionaryTable.get(docWord);

           if (fromDic == null) {
               wordsNotFound.put(docWord, docWord);
           }
       }
       System.out.println("Words not found in dictionary: ");
       Set<String> keys = wordsNotFound.keySet();
       for(String key: keys){
           System.out.println(count+++": "+wordsNotFound.get(key));
       }

  printStats(dictionaryTable, numberOfWords);

   }

}

Output for above program:

Words not found in dictionary:
1: hello
2: hen
3: god
minimum maximum mean
17 20 18.5

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote