Hi everybody I need some professional help from experienced people. I am writing a program in C++ about a game. I have to specify a class Questions with attributes question, answers and difficulty. In the program i should have methods add, edit, select, search, print and remove. The problem that i have is that i have to work dynamically with these questions and when i choose from the menu save, just then to save everything into the file. So far i have ideas for everything except what kind of container to use?? I thought that i can use "map" but the key ( this should be the number of question) is const and if i delete a question the keys after that will remain the same. I need when i delete a question this integer ( question number) to decrease with 1. Can you give me an advise what kind of container to use and if i need to put question number as an attribute into the class.
Thank you in advance for the help
Perhaps you should look at array or, considering you mention a dynamic requirement vector. You mention the number of the question needing to decrease by 1 if you delete a question. Map uses keys that remain the same i.e. don't decrease by 1 whilst vector, for instance will accomodate this better. I'm assuming that, say, if you delete question 5 then the fact that you want what was question 6 to now become question 5, question 7 to become 6 etc. With a map you could keep the keys 1,2,3,4,6,7,8.
In the above scenario u can use vector which would maintain the count of questions.Second thing if u want to provide some uniqueness to the question I think u should take a timestamp as variable in your question class which is updated when u create a question and will be overwritten if u modify that question. Thus ur count and uniqueness will remain intact.
Last Visit: 31-Dec-99 18:00 Last Update: 31-Aug-15 21:48