Need help with C++ programming and creating a map class. There are many function
ID: 3714692 • Letter: N
Question
Need help with C++ programming and creating a map class. There are many functions I will need done but I need help figuring out what map declaration of objects I need. These are the four functions ill be dealing with.
gram must have a Catalog class with the indicated functions:
AddCategory: Given a category number and name, add it to the catalog. It will have an empty product list. Return false if the category number already exists in the catalog, true otherwise.
AddProduct: Given a category number, a product number, and a product name, add the product to the catalog. Return false if the category number doesn’t exist in the catalog or if the product number already exists within the category, true otherwise.
GetCategoryCount: Return the number of categories in the catalog.
GetProductCount: Given a category number, return the number of products in the category; return -1 if the category doesn’t exist.
So how do i declare objects such as Product name, product name etc. I was thinking like - map<MyKey, MyValue> mymap;? But not sure how I should define the objects in my class.
Explanation / Answer
Here is some advice how to solve the problem.
hope this helps...
Thankyou... :)
First, don't store objects themselves in the map, store pointers to your objects.
Second, you need to give an instance of AddCategory to std::make_pair, not the class itself.
Here's how you go about storing pointers (Example):
String CurrentScene = "Scene_Branding";
map<string,Scene*>Scenes;
Scenes.insert(std::make_pair("Scene_Branding",new Scene_Branding()));
Note: please read it and understand carefully...
Thankyou.:)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.