[system] / trunk / webwork / system / courseScripts / PGchoicemacros.pl Repository:
ViewVC logotype

Annotation of /trunk/webwork/system/courseScripts/PGchoicemacros.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5 - (view) (download) (as text)

1 : gage 5 #!/usr/local/bin/perl
2 : sam 2 BEGIN{
3 :     be_strict;
4 :     }
5 :    
6 :     package main;
7 :    
8 :    
9 :     =head1 NAME
10 :    
11 :     PGchoicemacros.pl --- located in the courseScripts directory
12 :    
13 :    
14 :     =head1 SYNPOSIS
15 :    
16 :     =for html
17 :     There are two types of choice macros. The older versions are simply scripts. The newer versions involve the <a href='List'>List</a> class and its sub-classes and the use of objects based on these classes. The list sub-classes are: <a href='Match'>Match</a> which aids in setting up matching question and answer lists, <a href='Select'>Select</a> which aids in selecting and presenting a subset of questions with short answers (e.g. true/false questions) from a larger question set, and <a href='Multiple'>Multiple</a> which aids in setting up a standard style, one question, many answers type multiple choice question.
18 :    
19 :    
20 :     =head1 DESCRIPTION
21 :    
22 :     Typical use varies depending on the type of list being used.
23 :    
24 :     =for html
25 :     See the documentation for <a href='Multiple'>Multiple.pm</a>, <a href='Match'>Match.pm</a>, and <a href='Select'>Select.pm</a>
26 :    
27 :     =cut
28 :    
29 :    
30 :     =head2 Matching List macros
31 :    
32 :    
33 :     =head3 new_match_list
34 :    
35 :     Matching list object creation macro
36 :    
37 :     Useage:
38 :    
39 :     =for html
40 :     <PRE>
41 :     <I>$ml = new_match_list;</I></PRE>
42 :    
43 :     Which is equivalent to the following direct call to Match
44 :    
45 :     =for html
46 :     <PRE>
47 :     <I>$ml = new Match(random(1,2000,1), ~~&std_print_q, ~~&std_print_a);</I></PRE>
48 :    
49 :     =for html
50 :     Either call will create a matching list object in the variable $ml. ( $ml
51 :     cannot be a my variable if it is to be used within a
52 :     BEGIN_TEXT/END_TEXT block. The printing methods are passed as references (~~ in PG equals \ in perl) to
53 :     subroutines so that no matter what printing subroutines are used, those subroutines can be used by saying
54 :     $ml->print_q and $ml->print_a. This also means that other subroutines can be used instead of the default ones. An
55 :     example of how to do this is demonstrated with <a href="PGchoicemacros#pop_up_list_print_q">pop_up_list_print_q</a> below.
56 :    
57 :    
58 :     =for html
59 :     <P>See the documentation for <a href='Match'>Match.pm</a> to see how to use
60 :     this object to create a matching question.
61 :    
62 :    
63 :     =head4 std_print_q
64 :    
65 :     Standard method for printing questions
66 :    
67 :     =for html
68 :     This simple printing routine is used to print the questions for each of the three sub-classes of List. When a match list, select list, or multiple choice object is created, a reference to std_print_q is passed to that object so that it can be used from within the object later.
69 :    
70 :     std_print_q checks which mode the user is trying to print the questions from and returns the appropriately formatted string.
71 :    
72 :    
73 :     =head4 std_print_a
74 :    
75 :     Standard method for printing answers with answer boxes
76 :    
77 :     This simple printing routine is used to print the answers for matching lists
78 :     (and technically select list, even though answers are not printed with a select
79 :     list). When a match list or select list object is created, a reference to
80 :     std_print_q is passed to that object so that it can be used from within the
81 :     object later.
82 :    
83 :     std_print_a checks which mode the user is trying to print the answers from and
84 :     returns the appropriately formatted string.
85 :    
86 :    
87 :     =head2 Select List macros
88 :    
89 :    
90 :     =head3 new_select_list
91 :    
92 :     Select list object creation macro
93 :    
94 :     Useage:
95 :    
96 :     =for html
97 :     <PRE>
98 :     <I>$sl = new_select_list;</I></PRE>
99 :    
100 :     Which is equivalent to this direct call to Select
101 :    
102 :     =for html
103 :     <PRE>
104 :     <I>$sl = new Select(random(1,2000,1), ~~&std_print_q, ~~&std_print_a);</I></PRE>
105 :    
106 :     =for html
107 :     Either call will create a select list object in the variable $sl. ( Note that
108 :     $sl cannot be a my variable if it is to be used within a BEGIN_TEXT/END_TEXT
109 :     block.) The printing methods are passed as references (~~ in PG equals \ in
110 :     perl) to subroutines so that no matter what printing subroutines are used,
111 :     those subroutines can be used by saying $sl->print_q and $sl->print_a. This
112 :     also means that other subroutines can be used instead of the default ones. An
113 :     example of how to do this is demonstrated with <a href="PGchoicemacros#pop_up_list_print_q">pop_up_list_print_q</a> below.
114 :    
115 :    
116 :     =for html
117 :     <P>See the documentation for <a href='Select'>Select.pm</a> to see how to use this
118 :     object to create a true/false question.
119 :    
120 :    
121 :     =head4 std_print_q
122 :    
123 :     Standard method for printing questions with answer boxes
124 :    
125 :     See std_print_q under Matching Lists above.
126 :    
127 :    
128 :     =head4 std_print_a
129 :    
130 :     This is only intended to be used for debugging as there is rarely a reason to
131 :     print out the answers to a select list.
132 :    
133 :     See std_print_a under Matching Lists above.
134 :    
135 :    
136 :     =head3 new_pop_up_select_list
137 :    
138 :     Select list object creation macro
139 :    
140 :     Useage:
141 :    
142 :     =for html
143 :     <PRE>
144 :     <I>$sl = new_pop_up_select_list;</I></PRE>
145 :    
146 :     Which is equivalent to this direct call to Select
147 :    
148 :     =for html
149 :     <PRE>
150 :     <I>$sl = new Select(random(1,2000,1), ~~&pop_up_list_print_q, ~~&std_print_a);</I></PRE>
151 :    
152 :     =for html
153 :     Either call will create a select list object in the variable $sl. ( Note that
154 :     $sl cannot be a my variable if it is to be used within a BEGIN_TEXT/END_TEXT
155 :     block.) The printing methods are passed as references (~~ in PG equals \ in
156 :     perl) to subroutines so that no matter what printing subroutines are used,
157 :     those subroutines can be used by saying $sl->print_q and $sl->print_a. This
158 :     also means that other subroutines can be used instead of the default ones.
159 :    
160 :     =for html
161 :     <P>See the documentation for <a href='Select'>Select.pm</a> to see how to use this
162 :     object to create a true/false question.
163 :    
164 :    
165 :     =head4 std_print_q
166 :    
167 :     Standard method for printing questions with answer boxes
168 :    
169 :     See std_print_q under Matching Lists above.
170 :    
171 :    
172 :     =head4 pop_up_list_print_q
173 :    
174 :     Alternate method for print questions with pop up lists.
175 :    
176 :     Useage:
177 :    
178 :     This printing routine is used to print the questions for a true/false or other
179 :     select list with a preceding pop up list of possible answers. A list of values
180 :     and labels need to be given to the pop_up_list so that the intended answer is
181 :     returned when a student selects an answer form the list. Notethe use of => to
182 :     associate the values on the left with the labels on the right, this means that,
183 :     for instance, the student will see the word True in the pop_up_list but the
184 :     answer that is returned to the grader is T, so that it corresponds with what
185 :     the professor typed in as the answer when using $sl->qa('blah blah', 'T');
186 :    
187 :     =for html
188 :     <PRE>
189 :     <I>$sl->ra_pop_up_list([</I>value<I> => </I>label<I>,
190 :     T => 'True',
191 :     F => 'False']);</I></PRE>
192 :    
193 :    
194 :     =head4 std_print_a
195 :    
196 :     This is only intended to be used for debugging as there is rarely a reason to
197 :     print out the answers to a select list.
198 :    
199 :     See std_print_a under Matching Lists above.
200 :    
201 :    
202 :     =head2 Multiple Choice macros
203 :    
204 :    
205 :     =head3 new_multiple_choice
206 :    
207 :     Multiple choice object creation macro
208 :    
209 :     Useage:
210 :    
211 :     =for html
212 :     <PRE>
213 :     <I>$mc = new_multiple_choice;</I></PRE>
214 :    
215 :     Which is equivalent to this direct call to Multiple
216 :    
217 :     =for html
218 :     <PRE>
219 :     <I>$mc = new Multiple(random(1,2000,1), ~~&std_print_q, ~~&std_print_a);</I></PRE>
220 :    
221 :     Either call will create a multiple choice object in the variable $mc. Note that
222 :     $mc cannot be a my variable if it is to be used within a BEGIN_TEXT/END_TEXT
223 :     block.
224 :    
225 :     =for html
226 :     <P>See the documentation for <a href='Multiple'>Multiple.pm</a> to see how to use
227 :     this object to create a multiple choice question.
228 :    
229 :    
230 :     =head4 std_print_q
231 :    
232 :     Standard method for printing questions
233 :    
234 :     See std_print_q under Matching Lists above.
235 :    
236 :    
237 :     =head4 radio_print_a
238 :    
239 :     Method for printing answers with radio buttons
240 :    
241 :     This simple printing routine is used to print the answers to multiple choice
242 :     questions in a bulleted style with radio buttons preceding each possible answer.
243 :     When a multiple choice object is created, a reference to radio_print_a is passed
244 :     to that object so that it can be used from within the object later.
245 :    
246 :     radio_print_a checks which mode the user is trying to print the answers from and
247 :     returns the appropriately formatted string.
248 :    
249 :    
250 :     =head3 new_checkbox_multiple_choice
251 :    
252 :     Checkbox multiple choice object creation macro
253 :    
254 :     Useage:
255 :    
256 :     =for html
257 :     <PRE>
258 :     <I>$cmc = new_checkbox_multiple_choice;</I></PRE>
259 :    
260 :     Which is equivalent to this direct call to Multiple
261 :    
262 :     =for html
263 :     <PRE>
264 :     <I>$cmc = new Multiple(random(1,2000,1), ~~&std_print_q, ~~&checkbox_print_a);</I></PRE>
265 :    
266 :     Either call will create a checkbox multiple choice object in the variable $cmc. Note that
267 :     $cmc cannot be a my variable if it is to be used within a BEGIN_TEXT/END_TEXT
268 :     block.
269 :    
270 :     =for html
271 :     <P>See the documentation for <a href='Multiple'>Multiple.pm</a> to see how to use
272 :     this object to create a multiple choice question.
273 :    
274 :    
275 :     =head4 std_print_q
276 :    
277 :     Standard method for printing questions
278 :    
279 :     See std_print_q under Matching Lists above.
280 :    
281 :    
282 :     =head4 checkbox_print_a
283 :    
284 :     Method for printing answers with radio buttons
285 :    
286 :     This simple printing routine is used to print the answers to multiple choice
287 :     questions in a bulleted style with checkboxes preceding each possible answer.
288 :     When a multiple choice object is created, a reference to checkbox_print_a is passed
289 :     to that object so that it can be used from within the object later.
290 :    
291 :     checkbox_print_a checks which mode the user is trying to print the answers from and
292 :     returns the appropriately formatted string.
293 :    
294 :    
295 :    
296 :     =cut
297 :    
298 :     #Useage: $ml = new_match_list
299 :     #Note that $ml cannot be a my variable if used within a BEGIN_TEXT/END_TEXT block
300 :     sub new_match_list {
301 :     new Match(random(1,2000,1), \&std_print_q, \&std_print_a);
302 :     }
303 :    
304 :     #Useage: $sl = new_select_list
305 :     #Note that $sl cannot be a my variable if used within a BEGIN_TEXT/END_TEXT block
306 :     sub new_select_list {
307 :     new Select(random(1,2000,1), \&std_print_q, \&std_print_a);
308 :     }
309 :    
310 :     #Useage: $pusl = new_pop_up_select_list
311 :     sub new_pop_up_select_list {
312 :     new Select(random(1,2000,1), \&pop_up_list_print_q, \&std_print_a);
313 :     }
314 :    
315 :    
316 :     #Useage: $mc = new_multiple_choice
317 :     #Note that $mc cannot be a my variable if used within a BEGIN_TEXT/END_TEXT block
318 :     sub new_multiple_choice {
319 :     new Multiple(random(1,2000,1), \&std_print_q, \&radio_print_a);
320 :     }
321 :    
322 :     #Useage: $mcc = new_checkbox_multiple_choice
323 :     sub new_checkbox_multiple_choice {
324 :     new Multiple(random(1,2000,1), \&std_print_q, \&checkbox_print_a);
325 :     }
326 :    
327 :     #Useage: $sl->rf_print_a(~~&pop_up_list_print_q);
328 :     # $sl->ra_pop_up_list([</I>value<I> => </I>label<I>, T => 'True', F => 'False']);
329 :     sub pop_up_list_print_q {
330 :     my $self = shift;
331 :     my (@questions) = @_;
332 :     my $length = $self->{ans_rule_len};
333 :     my @list = @{$self->{ra_pop_up_list} };
334 :     my $out = "";
335 :    
336 :     if ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth') {
337 :     my $i=1; my $quest;
338 :     foreach $quest (@questions) {
339 :     $out.= "\n<p>" . pop_up_list(@list) . "&nbsp;<B>$i.</B> $quest";
340 :     $i++;
341 :     }
342 :     $out .= "<br>\n";
343 :     } elsif ($main::displayMode eq 'Latex2HTML') {
344 :     my $i=1; my $quest;
345 :     foreach $quest (@questions) {
346 :     $out.= " \\begin{rawhtml}<p><B>\\end{rawhtml}" . pop_up_list(@list) . " $i. \\begin{rawhtml}</B>\\end{rawhtml} $quest";
347 :     $i++;
348 :     }
349 :     $out .= " \\begin{rawhtml}<BR>\\end{rawhtml} ";
350 :     } elsif ($main::displayMode eq 'TeX') {
351 :     $out = "\n\\par\\begin{enumerate}\n";
352 :     my $i=1; my $quest;
353 :     foreach $quest (@questions) {
354 :     $out .= "\\item[" . pop_up_list(@list) . "$i.] $quest\n";
355 :     $i++;
356 :     }
357 :     $out .= "\\end{enumerate}\n";
358 :     } else {
359 :     $out = "Error: PGchoicemacros: pop_up_list_print_q: Unknown displayMode: $main::displayMode.\n";
360 :     }
361 :     $out;
362 :    
363 :     }
364 :    
365 :     #Standard method of printing answers in a matching list
366 :     sub std_print_a {
367 :     my $self = shift;
368 :     my(@array) = @_;
369 :     my $i = 0;
370 :     my $out= &main::M3(
371 :     "\\begin{enumerate}\n",
372 :     " \\begin{rawhtml} <OL TYPE=\"A\" VALUE=\"1\"> \\end{rawhtml} ",
373 :     "<OL COMPACT TYPE=\"A\" START=\"1\">\n"
374 :     ) ;
375 :     my $elem;
376 :     foreach $elem (@array) {
377 :     $out .= &main::M3(
378 :     "\\item[$main::ALPHABET[$i].] $elem\n",
379 :     " \\begin{rawhtml} <LI> \\end{rawhtml} $elem ",
380 :     "<LI> $elem\n"
381 :     ) ;
382 :     $i++;
383 :     }
384 :     $out .= &main::M3(
385 :     "\\end{enumerate}\n",
386 :     " \\begin{rawhtml} </OL>\n \\end{rawhtml} ",
387 :     "</OL>\n"
388 :     ) ;
389 :     $out;
390 :    
391 :     }
392 :    
393 :    
394 :     #Alternate method of printing answers as a list of radio buttons for multiple choice
395 :     #radio_print_a2 is used instead now
396 :     # sub radio_print_a {
397 :     # my $self = shift;
398 :     # my (@answers) = @_;
399 :     # my $num = ++$main::ans_rule_count;
400 :     # my $out = "";
401 :     # if ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth') {
402 :     # my $ans = shift @answers;
403 :     # $out .= "\n<BR>" . '&nbsp;' x 5 . NAMED_ANS_RADIO(NEW_ANS_NAME($num), $ans, $ans);
404 :     # foreach $ans (@answers) {
405 :     # $out.= "\n<BR>" . '&nbsp;' x 5 . NAMED_ANS_RADIO_OPTION(ANS_NUM_TO_NAME($num), $ans, $ans);
406 :     # }
407 :     # $out .= "<br>\n";
408 :     # } elsif ($main::displayMode eq 'Latex2HTML') {
409 :     # my $ans = shift @answers;
410 :     # $out .= "\\begin{rawhtml}<BR>\\end{rawhtml}" . NAMED_ANS_RADIO(NEW_ANS_NAME($num), $ans, $ans);
411 :     # foreach $ans (@answers) {
412 :     # $out.= "\\begin{rawhtml}<BR>\\end{rawhtml}" . NAMED_ANS_RADIO_OPTION(ANS_NUM_TO_NAME($num), $ans, $ans);
413 :     # }
414 :     # $out .= " \\begin{rawhtml}<BR>\\end{rawhtml} ";
415 :     # } elsif ($main::displayMode eq 'TeX') {
416 :     # $out = "\n\\par\\begin{itemize}\n";
417 :     # my $ans;
418 :     # foreach $ans (@answers) {
419 :     # $out .= "\\item[" . $ans . "\n";
420 :     # }
421 :     # $out .= "\\end{itemize}\n";
422 :     # } else {
423 :     # $out = "Error: PGchoicemacros: match_questions_list_varbox: Unknown displayMode: $main::displayMode.\n";
424 :     # }
425 :     # $out;
426 :     #
427 :     # }
428 :    
429 :    
430 :     #Alternate method of printing answers as a list of radio buttons for multiple choice
431 :     sub radio_print_a {
432 :     my $self = shift;
433 :     my (@answers) = @_;
434 :     my $out = "";
435 :     my $i =0;
436 :     my @in = ();
437 :     if ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth') {
438 :     foreach my $ans (@answers) {
439 :     push (@in, ($main::ALPHABET[$i], "<B> $main::ALPHABET[$i]. </B> $ans"));
440 :     $i++;
441 :     }
442 :     my @radio_buttons = ans_radio_buttons(@in);
443 :     $out = "\n<BR>" . join "\n<BR>", @radio_buttons;
444 :     $out .= "<BR>\n";
445 :     } elsif ($main::displayMode eq 'Latex2HTML') {
446 :     foreach my $ans (@answers) {
447 :     push (@in, ($main::ALPHABET[$i], "\\begin{rawhtml}<B> $main::ALPHABET[$i]. </B> \\end{rawhtml} $ans"));
448 :     $i++;
449 :     }
450 :     my @radio_buttons = ans_radio_buttons(@in);
451 :     $out = "\\begin{rawhtml}<BR>\\end{rawhtml}" . join "\\begin{rawhtml}<BR>\\end{rawhtml}", @radio_buttons;
452 :     $out .= " \\begin{rawhtml}<BR>\\end{rawhtml} ";
453 :     } elsif ($main::displayMode eq 'TeX') {
454 :     foreach my $ans (@answers) {
455 :     push (@in, ($main::ALPHABET[$i], "$main::ALPHABET[$i]. $ans"));
456 :     $i++;
457 :     }
458 :     my @radio_buttons = ans_radio_buttons(@in);
459 :     #$out = "\n\\par\\begin{itemize}\n";
460 :     $out .= join '', @radio_buttons;
461 :     #$out .= "\\end{itemize}\n";
462 :     } else {
463 :     $out = "Error: PGchoicemacros: radio_print_a: Unknown displayMode: $main::displayMode.\n";
464 :     }
465 :     $out;
466 :    
467 :     }
468 :    
469 :     #Second alternate method of printing answers as a list of radio buttons for multiple choice
470 :     #Method for naming radio buttons is no longer round about and hackish
471 :     sub checkbox_print_a {
472 :     my $self = shift;
473 :     my (@answers) = @_;
474 :     my $out = "";
475 :     my $i =0;
476 :     my @in = ();
477 :     if ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth') {
478 :     foreach my $ans (@answers) {
479 :     push (@in, ($main::ALPHABET[$i], "<B> $main::ALPHABET[$i]. </B> $ans"));
480 :     $i++;
481 :     }
482 :     my @checkboxes = ans_checkbox(@in);
483 :     $out = "\n<BR>" . join "\n<BR>", @checkboxes;
484 :     $out .= "<BR>\n";
485 :     } elsif ($main::displayMode eq 'Latex2HTML') {
486 :     foreach my $ans (@answers) {
487 :     push (@in, ($main::ALPHABET[$i], "\\begin{rawhtml}<B> $main::ALPHABET[$i]. </B> \\end{rawhtml} $ans"));
488 :     $i++;
489 :     }
490 :     my @checkboxes = ans_checkbox(@in);
491 :     $out = "\\begin{rawhtml}<BR>\\end{rawhtml}" . join "\\begin{rawhtml}<BR>\\end{rawhtml}", @checkboxes;
492 :     $out .= " \\begin{rawhtml}<BR>\\end{rawhtml} ";
493 :     } elsif ($main::displayMode eq 'TeX') {
494 :     foreach my $ans (@answers) {
495 :     push (@in, ($main::ALPHABET[$i], "$main::ALPHABET[$i]. $ans"));
496 :     $i++;
497 :     }
498 :     my @radio_buttons = ans_checkbox(@in);
499 :     #$out = "\n\\par\\begin{itemize}\n";
500 :     $out .= join '', @radio_buttons ;
501 :     #$out .= "\\end{itemize}\n";
502 :     } else {
503 :     $out = "Error: PGchoicemacros: checkbox_print_a: Unknown displayMode: $main::displayMode.\n";
504 :     }
505 :     $out;
506 :    
507 :     }
508 :    
509 :    
510 :     #Standard method of printing questions in a matching or select list
511 :     sub std_print_q {
512 :     my $self = shift;
513 :     my (@questions) = @_;
514 :     my $length = $self->{ans_rule_len};
515 :     my $out = "";
516 :     if ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth') {
517 :     my $i=1; my $quest;
518 :     foreach $quest (@questions) {
519 :     $out.= "\n<BR>" . ans_rule($length) . "<B>$i.</B> $quest";
520 :     $i++;
521 :     }
522 :     $out .= "<br>\n";
523 :     } elsif ($main::displayMode eq 'Latex2HTML') {
524 :     my $i=1; my $quest;
525 :     foreach $quest (@questions) {
526 :     $out.= " \\begin{rawhtml}<BR>\\end{rawhtml} " . ans_rule($length) . "\\begin{rawhtml}<B>\\end{rawhtml} $i. \\begin{rawhtml}</B>\\end{rawhtml} $quest"; #"$i. $quest";
527 :     $i++;
528 :     }
529 :     $out .= " \\begin{rawhtml}<BR>\\end{rawhtml} ";
530 :     } elsif ($main::displayMode eq 'TeX') {
531 :     $out = "\n\\par\\begin{enumerate}\n";
532 :     my $i=1; my $quest;
533 :     foreach $quest (@questions) {
534 :     $out .= "\\item[" . ans_rule($length) . "$i.] $quest\n";
535 :     $i++;
536 :     }
537 :     $out .= "\\end{enumerate}\n";
538 :     } else {
539 :     $out = "Error: PGchoicemacros: std_print_q: Unknown displayMode: $main::displayMode.\n";
540 :     }
541 :     $out;
542 :    
543 :     }
544 :    
545 :    
546 :     #legacy macros
547 :     #these are only needed for backward compatibility and should be taken out when no longer needed
548 :     #except for NchooseK which has become common enough that it should probably be moved to a
549 :     #different macros file and given some documentation
550 :     sub qa {
551 :     my($questionsRef,$answersRef,@questANDanswer) = @_;
552 :     while (@questANDanswer) {
553 :     push(@$questionsRef,shift(@questANDanswer));
554 :     push(@$answersRef,shift(@questANDanswer));
555 :    
556 :     }
557 :     }
558 :    
559 :     sub invert {
560 :     my @array = @_;
561 :     my @out = ();
562 :     my $i;
563 :     for ($i=0;$i<=$#array;$i++) {
564 :     $out[$array[$i]]=$i;
565 :     }
566 :     @out;
567 :     }
568 :    
569 :     sub NchooseK {
570 :     my($n,$k)=@_;;
571 :     my @array = 0..($n-1);
572 :     my @out = ();
573 :     while (@out<$k) {
574 :     push(@out, splice(@array, random(0,$#array,1) , 1) );
575 :     }
576 :     @out;
577 :     }
578 :    
579 :     sub shuffle {
580 :     my ($i) = @_;
581 :     my @out = &NchooseK($i,$i);
582 :     @out;
583 :     }
584 :    
585 :     sub match_questions_list {
586 :     my (@questions) = @_;
587 :     my $out = "";
588 :     if ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth') {
589 :     my $i=1; my $quest;
590 :     foreach $quest (@questions) {
591 :     $out.= "\n<BR>" . ans_rule(4) . "<B>$i.</B> $quest";
592 :     $i++;
593 :     }
594 :     $out .= "<br>\n";
595 :     } elsif ($main::displayMode eq 'Latex2HTML') {
596 :     my $i=1; my $quest;
597 :     foreach $quest (@questions) {
598 :     $out.= " \\begin{rawhtml}<BR>\\end{rawhtml} " . ans_rule(4) . "\\begin{rawhtml}<B>\\end{rawhtml} $i. \\begin{rawhtml}</B>\\end{rawhtml} $quest"; #"$i. $quest";
599 :     $i++;
600 :     }
601 :     $out .= " \\begin{rawhtml}<BR>\\end{rawhtml} ";
602 :     } elsif ($main::displayMode eq 'TeX') {
603 :     $out = "\n\\par\\begin{enumerate}\n";
604 :     my $i=1; my $quest;
605 :     foreach $quest (@questions) {
606 :     $out .= "\\item[" . ans_rule(3) . "$i.] $quest\n";
607 :     $i++;
608 :     }
609 :     $out .= "\\end{enumerate}\n";
610 :     } else {
611 :     $out = "Error: PGchoicemacros: match_questions_list: Unknown displayMode: $main::displayMode.\n";
612 :     }
613 :     $out;
614 :     }
615 :    
616 :    
617 :    
618 :     sub match_questions_list_varbox {
619 :     my ($length, @questions) = @_;
620 :     my $out = "";
621 :     if ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth') {
622 :     my $i=1; my $quest;
623 :     foreach $quest (@questions) {
624 :     $out.= "\n<BR>" . ans_rule($length) . "<B>$i.</B> $quest";
625 :     $i++;
626 :     }
627 :     $out .= "<br>\n";
628 :     } elsif ($main::displayMode eq 'Latex2HTML') {
629 :     my $i=1; my $quest;
630 :     foreach $quest (@questions) {
631 :     $out.= " \\begin{rawhtml}<BR>\\end{rawhtml} " . ans_rule($length) . "\\begin{rawhtml}<B>\\end{rawhtml} $i. \\begin{rawhtml}</B>\\end{rawhtml} $quest"; #"$i. $quest";
632 :     $i++;
633 :     }
634 :     $out .= " \\begin{rawhtml}<BR>\\end{rawhtml} ";
635 :     } elsif ($main::displayMode eq 'TeX') {
636 :     $out = "\n\\par\\begin{enumerate}\n";
637 :     my $i=1; my $quest;
638 :     foreach $quest (@questions) {
639 :     $out .= "\\item[" . ans_rule($length) . "$i.] $quest\n";
640 :     $i++;
641 :     }
642 :     $out .= "\\end{enumerate}\n";
643 :     } else {
644 :     $out = "Error: PGchoicemacros: match_questions_list_varbox: Unknown displayMode: $main::displayMode.\n";
645 :     }
646 :     $out;
647 :     }
648 :    
649 :    
650 :    
651 :     1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9