객관식 시험 유형 앱을 만들려고합니다. 그래서 같은 구조 .txt 파일의 각 문제의 질문과 선택과 대답을 :색인이있는 배열을 임의로 그룹화 (예 : 0-5가 함께 있어야 함)
Question#1
choice A
choice B
choice C
choice D
Answer#1
Question#2
choice A
choice B
etc. etc.
목표는 백 이상 질문과 문제 은행으로이하는 것입니다. 이 모든 정보를 읽을 수 있도록 배열을 준비했습니다. 무작위로 추출해야하지만 질문 # 1을 그대로 # 1로 유지하는 방식으로해야합니다 (질문 2의 선택 및 답변 바로 아래에 올 수 있습니다). 이것이 가능합니까?
아이디어는 100 개의 질문을 무작위로 추출하고 "연습 세션"을 위해 처음 50 개의 질문 (선택 사항과 답변을 그대로 유지)을 사용하는 것이 었습니다.
대단히 감사합니다.
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];