[system] / trunk / webwork / system / courseScripts / Match.pm Repository:
ViewVC logotype

View of /trunk/webwork/system/courseScripts/Match.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (download) (as text) (annotate)
Thu Jun 14 17:08:51 2001 UTC (11 years, 11 months ago) by sam
File size: 6858 byte(s)
initial import

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9