I am trying to create a multiple choice exam type app. I have the questions and choices and answer of each problem in a .txt file structured like so:
Question#1
choice A
choice B
choice C
choice D
Answer#1
Question#2
choice A
choice B
etc. etc.
The goal is to have this as a question bank with over a hundred questions. I have an array set up to read all this info. I need to randomize it but I need to do so in a way that will keep Question#1 to Answer#1 intact (so that Question 2 with its choices and answers right beneath it might come first). Is this possible at all?
The idea was to randomize a hundred questions and say take the first 50 questions (with their choices and answers intact) for a “practice session.”
Thank you very much.
Here’s the code:
if ([typeOfTest isEqualToString:@"SelectedExam"]) {
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"SelectedExam" ofType:@"txt"];
NSString *SelectedExamBank = [[NSString alloc] initWithContentsOfFile:filePath
encoding:NSUTF8StringEncoding error:NULL];
NSString* theBank = SelectedExamBank;
...
NSArray *multipleChoicePractice = [theBank componentsSeparatedByString:@"\n"];
//Calculating indexes while Question number would be in increments of 6
//(question 1 = index 0, question 2 = index 6, question 3 = index 12 etc)
choiceAindex = questionNumber + 1;
choiceBindex = questionNumber + 2;
choiceCindex = questionNumber + 3;
choiceDindex = questionNumber + 4;
theAnswer = [multipleChoicePractice objectAtIndex:answerChecker];
answerChecker = questionNumber + 5;
...
//q1 is the question and cA ... cD are choices
q1 = [multipleChoicePractice objectAtIndex:questionNumber];
cA = [multipleChoicePractice objectAtIndex:choiceAindex];
cB = [multipleChoicePractice objectAtIndex:choiceBindex];
cC = [multipleChoicePractice objectAtIndex:choiceCindex];
cD = [multipleChoicePractice objectAtIndex:choiceDindex];
Without seeing the code, it would be tough to figure out a solution. Personally, I would suggest creating a new Question class that holds the question, choices, and answer. Then, you could simply randomize the questions within each instance of the class, and keep an array of Questions.