Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do you Hashed Dictionary type written in C++ code? Please help Implementing the dictionary You can use any of the three main techniques -

image text in transcribedimage text in transcribedHow do you Hashed Dictionary type written in C++ code? Please help

Implementing the dictionary You can use any of the three main techniques - Unsorted Dictionary. Sorted Dictionary or Hashed Dictionary. My preference is for hashed, as that should give the best performance. Use either the hashpjw() or my weighted hash function For this project, the KeyType must be string and the ValueType must be Fraction Testing the dictionary Write a short program that creates a Dictionary. Then, use a loop to presenta menu to the user. The menu should provide options for all Dictionary operations-insert, remove, search, update. isEmpty, size, clear. If you chose to implement the additional operations, present those in the menu as well (the getFirstKey and getNextKey should be one option that does the loop). Perform the chosen action and continue in the loop until the user chooses to quit. Goal Create a Dictionary class and a program that tests it. Details A Dictionary is a basic container class that supports the five basic operations - create, destroy. clear, isEmpty and size - as well as the following four operations: void insert(KeyType k,Value Type v) Insert the key-value pair (k. v) into the dictionary. If k already exists, then throw a domain_error exception. .void remove (KeyType k) Remove the key k and its corresponding value. If k is not in the dictionary. then throw a domain_error exception Value Type search(KeyType k) Search for the key k. If found, return the corresponding value. If not found, throw a domain_error exception. void update (KeyType k,Value Type v) Search for the key k. If found, change its corresponding value to v. If not found, throw a domain_error exception In addition, a Dictionary can support the following operations: void forceUpdate (KeyType k, Value Type v) Same as update(), but if the key is not found, the pair is inserted into the dictionary bool getFirstKey(KeyType &k) Sets k to the first key in the dictionary. Refums false if the dictionary is er sempty .bool getNextKey(KeyType &k) Stores the next key found in k. Returns true if a key is found, false if no more keys exist. The intent of getFirstKey() and getNextKey() is to loop through all keys currently in the dictionary. Here's some example code: bool haveKey d.getFirstKey(); 2 while (haveKey){ 11 do something with k, like d. search(k) to get the value haveKey. d.getNextKey(); 3 4 For our purposes, the dictionary must be able to hold at least 100 key-value pairs

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started