MATLAB/Wikiquiz writer (MATLAB)/writefirstpage.m

function  [firstpagedone]= writefirstpage(quizarray,headertext,extralines, textline1,textline2)
%WRITEFIRSTPAGE writes the first page.  It is only one wikiquiz, preferably
%in the order of the readings.  It can be randomized by not using
%display=simple.
%with both random.
firstpagedone=false;
%start remove (comment out)
questioncount=size(quizarray,1);
%Output first page, with two wikiquizzes,
outputfilename = ['outputFolder/' headertext ' version A.txt'];
fout = fopen(outputfilename, 'w+');
%Output header
if extralines>0 
    s =textline1; 
    fprintf(fout,'%s\n',s); 
end;
%s ='* [[/Testbank/]]<ref>software by user:Clockworks</ref>';  fprintf(fout,'%s\n',s);
if extralines>1 
    s =textline2; 
    fprintf(fout,'%s\n',s); 
end;
s =['== ',headertext,' version A =='];  fprintf(fout,'%s\n',s);
s ='<quiz>';  fprintf(fout,'%s\n',s);  %Allows user to randomize
%Randomize answers but not questions
for questionindex = 1:questioncount
    questionposition=questionindex;%we are not randomizing question order
    answercount = cell2mat(quizarray(questionposition,2));
    orderofanswers=randperm(answercount);
    if answercount==2
        orderofanswers=[1 2];
    end
    s=char(quizarray(questionposition,1));
    fprintf(fout,'%s\n',s);% prints question
    for answerindex = 1:answercount
        answerposition=orderofanswers(answerindex);
        s=char(quizarray(questionposition,answerposition+2));
     fprintf(fout,'%s\n',s);%  prints answer
    end
    s=' ';
    fprintf(fout,'%s\n',s);
end
s ='</quiz>';  fprintf(fout,'%s\n',s);
%
% %Comment out this section if only one version is desired
% %RANDOMIZE BOTH QUESTINS AND ANSWERS
% s =['== ',headertext,' version B =='];  fprintf(fout,'%s\n',s);
% s ='<quiz display=simple>';  fprintf(fout,'%s\n',s);
%  orderofquestions=randperm(questioncount);
% for questionindex = 1:questioncount
%     questionposition=orderofquestions(questionindex);%we are  randomizing questions
%     answercount = cell2mat(quizarray(questionposition,2));
%     orderofanswers=randperm(answercount);
%     if answercount==2
%         orderofanswers=[1 2];
%     end
%     s=char(quizarray(questionposition,1));
%     fprintf(fout,'%s\n',s);% prints question
%     for answerindex = 1:answercount
%         answerposition=orderofanswers(answerindex);
%         s=char(quizarray(questionposition,answerposition+2));
%      fprintf(fout,'%s\n',s);%  prints answer
%     end
%     s=' ';
%     fprintf(fout,'%s\n',s);
% end
% s ='</quiz>';  fprintf(fout,'%s\n',s);
% %End section that was commented out to produce only one version
%
%
fclose(fout);
firstpagedone=true;

end