Hello for my C++ programming class I am programming a Dictionary program that allows the user to enter in definitions and stores them between 2 classes. Dictionary which will contain all my entries and Entry which will contain the definition for every word that the user inputs.

Now when they add a Definition they are asked for the word they want to add a definition too and if the word does not exist it will create a new Entry Object to store the information.

My problem is I want to be able to use the user inputted word to name the object and can not find a way to do it.

Example;
Word to Add Definition: Car
Car is a new word create new Object of Class Entry Car.
New Word to add Definition: Monopoly
Monopoly is a new word create a new Object of Class Entry called Monopoly.

Recommended Answers

All 4 Replies

Why do you want to do that? The name of the object is arbitrary, it's the data inside that is important.

To do something like that, I'd hashmap with the object containing the data as the value and the name as the key.

Of course it might not be needed at all.

The reason being is later I need to be able to search and find definitions in the dictionary and would like to just use a vector to call the object. Thinking about it though is there a way to create a vector of objects so that I would be able to add objects to the vector so that I can sort and call on them later.

Dictionaries are generally represented by a form of Map as mentioned in previous posts. your solution will wind up with you having many thousands of distinct objects, one for each word entered. this seems to me to be a bit messy. Try reading up on Maps before moving on...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.