I need to create a quiz for a dewey decimal system

Taahir10

New member
Joined
Nov 19, 2022
Messages
1
Programming Experience
Beginner
Hi guys,
I need to create a quiz for a dewey decimal system. I have decided to use listboxes to match the answers. However I'm not getting anywhere.
The case is as follows:
Create a txt file that has atleast 100 entries from dewey decimal call outs, must contain 1st level, 2nd level and 3rd level.
For each question, randomly select a third-level entry from the data, for example, 752 Color. Display only the description, not the call number.
b. Display four top-level options to the user to choose between, one of which must be the correct one and the other three randomly selected incorrect answers. For example: 000 General 400 Language 700 Arts & Recreation (Correct answer) 800 Literature
c. For the options, display both the call number and description. Display the options in numerical order by call number. d. If the user selects the correct option, show them four options from the next level until the most detailed level is reached.
e. If the user selects the wrong option anywhere along the way, indicate this and then ask the next question.

Can anyone please show me how to do this?
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
6,068
Location
Chesapeake, VA
Programming Experience
10+
We are not a code writing service. We will not do your homework for you. We can help guide you towards getting to a solution. Post your code (as text in code tags). Tell us what problem you are currently running into. Tell us what have already tried to solve the problem.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
6,068
Location
Chesapeake, VA
Programming Experience
10+
Your btnCheck_Click() is completely empty. What have you tried? What problem are you running into with your attempt?
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
6,068
Location
Chesapeake, VA
Programming Experience
10+
You'll need to explain to us how your LevelOne() method is supposed to work. I've been staring at it for 20 minutes and I'm having a hard time making heads or tails out of it to even advice how to do things. To me it seems overly complicated. A simpler approach would be something like the following pseudo code:
C#:
List<Node> candidates = GetLevelNodes(1);
List<Node> quizNodes = new();
do 4 times:
{
    int index = compute random index into candidates
    Make a copy the candidate node into the quizNodes -- do not just reference the candidate node
    remove item at index of the candidates;
}

for(int i = 2; i > 0; i--)
{
    int j = compute random number from 0 to i-1.
    swap quizNode[i].Value with quizNode[j].Value
}

sort quizNodes by Key.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
4,755
Location
Sydney, Australia
Programming Experience
10+
i don't have any matching values in my list boxes so I can't attempt that yet
Then why is it even there? You need to post the RELEVANT code. Explain what specific problem you need help with and post ALL and ONLY the code relevant to that problem. Every but of code you post that we don't need to see makes it harder for us to help you. If you can't narrow down the code to only what's relevant then you haven't spent enough time trying to work out what problem you're trying to solve, never mind solving it. One of the biggest reasons that beginners have trouble is that they try to solve multiple problems at once as though they were one and end up solving none. Divide and conquer. Break the problem down into the smallest parts you can and address each part individually. You then combine multiple solutions to the small problems into one solution for a bigger problem, massaging where they come together as required. This is basically problem solving 101 and is important to countless fields, but is critical to software development.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
6,068
Location
Chesapeake, VA
Programming Experience
10+
I had to leave in the middle of writing post #7, so I didn't get a chance to write some explanations for it.

Line 1 calls a another method that you need to write: GetLevelNodes(). The parameter passed in is what level needs to be retrieved. Passing in 1 returns all the level one nodes; passing in 2 returns all the level 2 nodes; etc. This method should return references to nodes that you had previously loaded into your tree or your nodes dictionary. Your choice. I personally think pulling from your dictionary would be easier than trying to find sibling nodes.

Anyway all nodes from a particular level will go into the candidates list after that method call.

Lines 3-8 randomly copies nodes from the candidates list into the quizNodes list. No duplicates will be put into the quiz nodes because we are randomly picking an item from the candidates, and then removing that item from the candidates. The iteration of the loop will only ever be able to pick a node from the remaining candidates. It's important to make a brand new node and copy the data from the chosen candidate instead of just taking a reference because of the succeeding lines 10-14. You will end up with 4 quiz nodes where their keys are in random order.

Lines 10-14 will loop from the third quiz node back to the second quiz node. During the first iteration, it will swap the description of the third quiz node with either the first or second quiz node. On the second iteration, it will swap the description of the second quiz node with the first quiz node. Since we are swapping descriptions, we want the swaps to only affect the copies, not the originals from the tree or the dictionary. This will effectively force incorrect answers for the first three quiz nodes, and guarantee a correct answer for the fourth quiz node.

Line 16 orders the quiz nodes in key ascending order as required by your assignment.

Later when it is time to check the user's answer, all you need to do is look in the nodes dictionary to see what the correct description is for the chosen key value. If the description found in nodes matches the description in the chosen quiz node, then the user selected the right answer.
 
Last edited:
Top Bottom