Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in c++ Goal Create a Dictionary class and a program that tests it. Details A Dictionary is a basic container class that supports the five

in c++
image text in transcribed
image text in transcribed
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, ValueType 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. 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: bool haveKey = d.getFirstKey(k); 2 while (haveKey){ // do something with k, like d. search(k) to get the value haveKey = d.getNextKey(K); S} For our purposes, the dictionary must be able to hold at least 100 key-value pairs. 3 4 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 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 Tur in your source code and Makefile

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Database Horse Betting The Road To Absolute Horse Racing 2

Authors: NAKAGAWA,YUKIO

1st Edition

B0CFZN219G, 979-8856410593

More Books

Students also viewed these Databases questions

Question

LO6 Define harassment and the role that HR plays in addressing it.

Answered: 1 week ago