Parent Directory
|
Revision Log
moved PG modules and macro files from webwork-modperl to pg -sam
1 #!/usr/bin/perl -w 2 #Construct for matching list. 3 #Inherits from List.pm 4 #VS 6/16/2000 5 6 =head1 NAME 7 8 Match.pm -- sub-class of List that implements a matching list. 9 10 All items accessed by $out = $ml -> item( $in ); 11 12 =head1 SYNOPSIS 13 14 Match.pm is intended to be used to create standard matching questions in which the the student is given a list of questions and a list of answers and is asked to match the correct answers to those questions. Some answers may be used more than once while others are not used at all. The order of answers is usually random but some answers can be appended to the end of the list in a set order (i.e. 'None of the above', 'All of the above'). Answers are not directly typed in but are given a corresponding letter that is the answer that the system expects. (i.e. 'the answer to #1 is A' not 'the answer to #1 is the square root of 2'). Also, students can be given different sets of questions (to avoid students sharing answers) by entering many questions and then using choose with a number less than the total so that each student only receive a sub-set of those questions. 15 16 =head1 DESCRIPTION 17 18 =head2 Variables and methods available to Match 19 20 =head3 Variables 21 22 questions # array of questions as entered using qa() 23 answers # array of answers as entered using qa() 24 extras # array of extras as entered using extra() 25 26 selected_q # randomly selected subset of "questions" 27 selected_a # the answers for the selected questions 28 selected_e # randomly selected subset of "extras" 29 30 ans_rule_len # determines the length of the answer blanks 31 # default is 4 32 33 slice # index used to select specific questions 34 shuffle # permutation array which can be applied to slice 35 # to shuffle the answers 36 37 inverted_shuffle # the inverse permutation array 38 39 rf_print_q # reference to any subroutine which should 40 # take ($self, @questions) as parameters and 41 # output the questions in a formatted string. 42 # If you want to change the way questions are 43 # printed, write your own print method and set 44 # this equal to a reference to to that method 45 # (i.e. $sl->rf_print_q(~~&printing_routine_q) ) 46 47 rf_print_a # reference to any subroutine which should 48 # take ($self, @answers) as parameters and 49 # output the answers in a formatted string. 50 # If you want to change the way answers are 51 # printed, write your own print method and set 52 # this equal to a reference to to that method 53 # (i.e. $sl->rf_print_a = ~~&printing_routine_a) 54 55 =head3 Methods 56 57 qa( array ) # accepts an array of strings which can be used 58 # for questions and answers 59 60 extra( array ) # accepts an array of strings which can be used 61 # as extra answers 62 63 print_q # yields a formatted string of question to be 64 # matched with answer blanks 65 print_a # yields a formatted string of answers 66 67 choose([3, 4], 1) # chooses questions indexed 3 and 4 and one other 68 # randomly 69 choose_extra([3, 4], 1) # choooses extra answers indexed 3 and 4 and one 70 # other 71 makeLast( array ) # accepts an array of strings (like qa) which will 72 # be forced to the end of the list of answers. 73 74 ra_correct_ans # outputs a reference to the array of correct answers 75 76 =head2 Usage 77 78 Create a match list using the new_match_list call. 79 80 =for html 81 <PRE> 82 <I>$ml = new_match_list</I></PRE> 83 84 Use qa() first to enter questions and answers in alternating pairs. Note that 85 multiple questions can have the same answer. Any duplicates will be eliminated. 86 87 =for html 88 <PRE> 89 <I>$ml->qa( 90 '\( x^2 \)', 91 'quadratic', 92 '\( x^3 \)', 93 'cubic', 94 '\( x^3/x \)', 95 'quadratic', 96 '\( log(x) \)', 97 'logarithmic', 98 '\( 2^x \)', 99 'None of the above', 100 );</I></PRE> 101 102 After you call qa you can use extra() to enter extra 'answers'. Again all 103 duplicates will be eliminated. 104 105 =for html 106 <PRE> 107 <I>$ml->extra( 108 'linear', 109 'quartic', 110 'really curvy', 111 );</I></PRE> 112 113 After calling extra you can use choose to select which questions and/or how many each student sees. This helps give students different sub-sets of the full question set so that students cannot cheat as easily. A list of numbers in brackets indicates which questions every student sees (counting starts with 0) and the final number outside of brackets is how many more questions should be randomly picked for each student. Though it is available, the use of selecting specific extra answers is not recommended for novices as the indexing is complicated (see below). 114 115 =for html 116 <PRE> 117 <I>$ml->choose([0], 1);</I></PRE> 118 119 would show the first question and a random question while 120 121 =for html 122 <PRE> 123 <I>$ml->choose(3);</I></PRE> 124 125 would show 3 random questions (but never call choose more than once). 126 127 After calling choose, use choose_extra to select which of the extra 'answers' 128 will be given to each student. Note that unused answers are dumped into the 129 list of extra 'answers' so the indexing may be difficult to grasp at first. 130 (This can be stopped by doing the following: $ml->dumpExtra = "";) 131 132 =for html 133 <PRE> 134 <I>$ml->choose_extra([0], 2);</I></PRE> 135 136 would show 3 extra answers besides the correct one note that these extra 137 answers may consist of answers from the questions that were not used. 138 139 After calling choose_extra you can use makeLast to add specific answers to the 140 end of the list of answers or to force already existing answers to be moved to 141 the end of the list. This is usually done for 'None of the above', or 'All of 142 the above' type answers. 143 144 =for html 145 <PRE> 146 <I>$ml->makeLast( 147 'All of the above', 148 'None of the above' 149 );</I></PRE> 150 151 If you want you can change the size of the answer boxes at any time (the default is 4). 152 153 =for html 154 <PRE> 155 <I>$ml->ans_rule_len(10);</I></PRE> 156 157 Now you would start your problem with a BEGIN_TEXT tag and print the questions 158 and answers with the print_q() and print_a() commands. Within the 159 BEGIN_TEXT/END_TEXT block, all calls to objects must be enclosed in \( \). 160 (The $PAR start a new paragraph by printing a blank line). 161 162 =for html 163 <PRE> 164 <I>BEGIN_TEXT 165 $PAR 166 \{ $ml->print_q() \} 167 $PAR 168 \{ $ml->print_a() \} 169 END_TEXT</I></PRE> 170 171 Now all that's left is sending the students answers to the answer evaluator 172 along with the correct answers so that the students answers can be checked and 173 a score can be given. This is done using ANS, an answer evaluator and the 174 ra_correct_ans variable. 175 176 =for html 177 <PRE> 178 <I>ANS(str_cmp($ml->ra_correct_ans));</I></PRE> 179 180 =cut 181 182 BEGIN { 183 be_strict(); 184 } 185 186 187 package Match; 188 189 @Match::ISA = qw( List ); 190 191 # *** Subroutines which overload List.pm *** 192 193 #sends letters for comparison instead of actual answers 194 sub ra_correct_ans { 195 my $self = shift; 196 my @ans = &List::ALPHABET( @{$self->{inverted_shuffle}} ); 197 \@ans; 198 } 199 200 1;
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |