Question
I need help creating a program in C++ that behaves like a dictionary in python. Example: id = {'miguel':4333, 'tom':3243, 'stacy':65443, 'robert':94340)} Here are some
I need help creating a program in C++ that behaves like a dictionary in python.
Example: id = {'miguel':4333, 'tom':3243, 'stacy':65443, 'robert':94340)}
Here are some messages and their outcomes:
id.keys()
['miguel','tom','stacy','robert'}
id.values()
[4333,3243,65443,94340]
id.items()
[('miguel',4333),('tom',3243),('stacy',65443),('robert',94349)]
also:
id.add('mark',1447) adds a pair to the dictionary
id.del('tom') removes the pair ('tom',3243)
id.in('mark') outputs true if mark is a key in grades at this moment
grades.get('tom') should return 3243
So the idea is now to define a class in C++ that behaves like a Python dictionary,
and which does the seven functions mentioned above.
The implementation should use a 'vector' to store the pairs. A pair could be
a vector, or a struct, or a class.
You can follow the pattern that a key is a string, and a value is an int.
No two pairs in a dictionary are allowed to have the same key.
You should overload the operator + to do the 'union' of two dictionaries.
If the dictionaries each contain the same key output an error message
if there is any kind of similar class in some version of C++, you should
ignore it.
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