Answered step by step
Verified Expert Solution
Question
1 Approved Answer
c++ Goal Create a Dictionary class and a program that tests it. Details A Dictionary is a basic container class that supports the five basic
c++
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, ValueType 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(Key Type 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,ValueType 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. Returns false if the dictionary is empty. 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: 1 bool haveKey = d.getFirstKey(k); 2 while (haveKey){ 3 // do something with k, like d. search(k) to get the value haveKey = d.getNextKey(); 5} For our purposes, the dictionary must be able to hold at least 100 key-value pairs. 4 simplementing 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 present a 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. What to turn in Tum in your source code and Makefile Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started