Question: Hello, I have a problem with my assignment of C++ class. I am learning templates now, but the level of this homework is too high
Hello, I have a problem with my assignment of C++ class. I am learning templates now, but the level of this homework is too high to me. Could you show me an example of solution ? I am doing it by myself, but I need a example of the whole solution for this assiginment
Part 1 A dictionary is a data structure specialized for searching by some keys. This structure maps unique keys to their values, so a key uniquely maps to only one value. While keys and Values can be of different data types, assume that all the keys are of the same type and the same for the values. For example, a dictionary may associate student IDs to their numeric grades. In this example keys are very probably of type string and values are floating-point numbers.
Define a class template for the dictionary type based on the following instructions: Consider a maximum size for your dictionary and define two arrays of that size one for the keys and one for the values. Since your dictionary does not necessarily have elements equal to the maximum value you considered, you must consider another attribute to store the actual number of elements in the dictionary. Complete your implementation by implementing the following methods: 1. A default constructor that creates an empty dictionary.
2. A method to add an element (i.e. a pair of key-value) to the dictionary. This method throws an exception if the dictionary is full. In case the key already exists in the dictionary, this method updates the value to the new value.
3. A method to retrieve the value associated with a key. This method throws an exception in case the key does not exist.
4. A method to check if a key exists in the dictionary.
5. A method to delete a pair of key-value from the dictionary. This method also throws an exception in case the provided key does not exist.
6. A method to overload the subscript operator (i.e. []) to retrieve a value associated with a key provided inside square brackets. This method also throws an exception if the specified key does not exist.
7. Overload the stream insertion operator (i.e. <<) to send a dictionary in the following format to an output stream: {(key1, value1), (key2, value2), (key3, value3), }
Part 2 Use the dictionary template you implemented in the previous part to write a program that creates a dictionary that associated the student IDs of a class to their final grades. This program then repeatedly asks user to enter an ID and displays the students grade on the screen if the specified ID exists or prints an appropriate message along with the content of the dictionary on the screen.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
