[system] / trunk / pg / lib / Multiple.pm Repository:
ViewVC logotype

View of /trunk/pg/lib/Multiple.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6346 - (download) (as text) (annotate)
Sat Jul 10 12:39:40 2010 UTC (8 years, 2 months ago) by gage
File size: 7818 byte(s)
Merging changes gage branch  gage_dev/pg

removed dependence on AUTOLOAD	which does not work well with newer versions of Safe.pm.  It wasn't needed 
in any case.  There remain other incompatibilies of WeBWorK with Safe.pm 2.27

Added more support for WARN_MESSAGE  and DEBUG_MESSAGE

Changed List.pm to ChoiceList.pm  to remove confusion with MathObjects List object

Additional support for geogebra applets



    1 
    2 #Construct for Multiple Choice.
    3 #Inherits from ChoiceList.pm
    4 #VS 6/16/2000
    5 
    6 
    7 =head1 NAME
    8 
    9 Multiple.pm -- sub-class of ChoiceList that implements a multiple choice question.
   10 
   11 All items accessed by $out=$mc->item($in);
   12 
   13 =head1 SYNOPSIS
   14 
   15 Multiple.pm is intended to be used to create one of two types of multiple choice
   16 questions. The regular multiple choice question is one question followed by a
   17 list of answers, only one of which is correct, printed in a bulleted form with
   18 radio buttons to select the correct answer.  The second type of of multiple choice
   19 question consists of one question followed by several answers bulleted with check
   20 boxes so that more than one answer can be selected if more than one answer exists.
   21 Each student will receive the same set of answers in a mostly random order (some
   22 answers can be forced to be at the end of list of answers, see makeLast() below).
   23 
   24 =head1 DESCRIPTION
   25 
   26 =head2 Variables and methods available to Multiple
   27 
   28 =head3 Variables
   29 
   30   questions     # array of questions as entered using qa()
   31   answers       # array of answers as entered using qa()
   32 
   33   selected_q      # randomly selected subset of "questions"
   34   selected_a      # the answers for the selected questions
   35 
   36   slice       # index used to select specific questions
   37   shuffle       # permutation array which can be applied to slice
   38             # to shuffle the answers
   39 
   40   inverted_shuffle  # the inverse permutation array
   41 
   42   rf_print_q      # reference to any subroutine which should
   43             # take ($self, @questions) as parameters and
   44             # output the questions in a formatted string.
   45             # If you want to change the way questions are
   46             # printed, write your own print method and set
   47             # this equal to a reference to to that method
   48             # (i.e. $sl->rf_print_q = ~~&printing_routine_q)
   49 
   50   rf_print_a      # reference to any subroutine which should
   51             # take ($self, @answers) as parameters and
   52             # output the answers in a formatted string.
   53             # If you want to change the way answers are
   54             # printed, write your own print method and set
   55             # this equal to a reference to to that method
   56             # (i.e. $sl->rf_print_a = ~~&printing_routine_a)
   57 
   58 =head3 Methods
   59 
   60   qa( array )     # accepts an array of strings which can be used
   61             # for the question and answers
   62 
   63   extra( array )    # accepts an array of strings which can be used
   64             # as extra answers
   65 
   66   print_q       # yields a formatted string of question to be
   67             # matched with answer blanks
   68   print_a       # yields a formatted string of answers
   69 
   70   choose([3, 4], 1) # chooses questions indexed 3 and 4 and one other
   71             # randomly
   72   makeLast( array ) # accepts an array of strings (like qa) which will
   73             # be forced to the end of the list of answers.
   74 
   75   correct_ans     # outputs a reference to the array of correct answers
   76 
   77 
   78 =head2 Usage
   79 
   80 
   81 =head3 Regular Multiple Choice
   82 
   83 Create a multiple choice question using the new_multiple_choice call.
   84 
   85 =for html
   86   <PRE>
   87   <I>$mc = new_multiple_choice</I>
   88   </PRE>
   89 
   90 Use qa() to enter the question and the correct answer. Any duplicates will be eliminated.
   91 
   92 =for html
   93    <PRE>
   94    <I>$mc->qa('\( x^2 \) is:', 'quadratic');</I></PRE>
   95 
   96 After calling qa you can use extra() to add in extra incorrect answers that (along with the
   97 correct answer) will be made into a random list of answers shown to the student.
   98 
   99 =for html
  100   <PRE>
  101   <I>$mc->extra(
  102     'cubic',
  103     'logarithmic',
  104     'exponential'
  105   );</I></PRE>
  106 
  107 
  108 If you want certain answers to be at the end of the list instead of having them be randomized
  109 you can use makeLast to add specific answers to the end of the list of answers or to force
  110 already existing answers to be moved to the end of the list.  This is usually done for
  111 'None of the above', or 'All of the above' type answers.  Note that if 'None of the above'
  112 is the correct answer then you must put it in qa() and then also makeLast() but the duplicate
  113 will be eliminated.  If more than one extra answer is added via makeLast, they are added
  114 in the same order they are given in makeLast.
  115 
  116 =for html
  117   <PRE>
  118   <I>$mc->makeLast(
  119     'All of the above',
  120     'None of the above'
  121   );</I></PRE>
  122 
  123 Now you would start your problem with a C<BEGIN_TEXT> tag and print the questions
  124 and answers with the print_q() and print_a() commands. Within the C<BEGIN_TEXT/END_TEXT block>,
  125 all calls to objects must be enclosed in \( \).
  126 (The $PAR start a new paragraph by printing a blank line).
  127 
  128 =for html
  129   <PRE>
  130   <I>BEGIN_TEXT
  131     $PAR
  132     \{ $mc->print_q() \}
  133     $PAR
  134     \{ $mc->print_a() \}
  135   END_TEXT</I></PRE>
  136 
  137 Now all that''s left is sending the students answers to the answer evaluator
  138 along with the correct answers so that the students answers can be checked and
  139 a score can be given.  This is done using C<ANS>, an answer evaluator and the
  140 C<correct_ans> variable.
  141 
  142 =for html
  143   <PRE>
  144   <I>ANS(radio_cmp($mc->correct_ans))</I></PRE>
  145 
  146 
  147 =head3 Checkbox Multiple Choice
  148 
  149 
  150 A checkbox multiple choice problem is identical to a regular multiple choice problem with only
  151 a few exceptions.
  152 
  153 First, you create the checkbox multiple choice object using the command:
  154 
  155 =for html
  156   <PRE>
  157   <I>$cmc = new_checkbox_multiple_choice</I></PRE>
  158 
  159 Then you would call qa() just as in a regular multiple choice object except that this time
  160 you can provide more than one answer
  161 
  162 =for html
  163    <PRE>
  164    <I>$cmc->qa(
  165         'Indicate all the functions that are anti-derivatives of \( 3x^2 \)',
  166         '\( x^3 \)',
  167         '\( x^3 - 57 \)',
  168         '\( 27 + x^3 \)'
  169   );</I></PRE>
  170 
  171 Then you would use extra() and makeLast() and create the problem just as with a regular multiple
  172 choice.  The only other difference is that at then end of the problem you would use checkbox_cmp()
  173 instead of radio_cmp().
  174 
  175 =for html
  176   <PRE>
  177   <I>ANS(radio_cmp($cmc->correct_ans))</I></PRE>
  178 
  179 
  180 =cut
  181 
  182 BEGIN {
  183   be_strict();
  184 }
  185 
  186 #use strict;
  187 package Multiple;
  188 
  189 @Multiple::ISA = undef;
  190 @Multiple::ISA = qw( Exporter ChoiceList );
  191 
  192 # *** Subroutines which overload ChoiceList.pm ***
  193 sub choose { warn "Multiple choice does not support choosing answers.\n(You can't use \$mc->choose().)"; }
  194 sub choose_extra { warn "Multiple choice does not support choosing answers.\n(You can't use \$mc->choose_extra().)"; }
  195 sub extras { warn "Extras() is not a method of Multiple.pm.\nUse the extra() method to add extra answers."; }
  196 
  197 sub qa {
  198   my $self = shift;
  199   my @input = @_;
  200 
  201   push( @{ $self->{questions} }, shift(@input) ); #one question
  202   push( @{ $self->{answers} }, @input );  #correct answer(s)
  203 
  204   $self->choose2(scalar(@{ $self->{answers} }));
  205 }
  206 
  207 sub extra {
  208   my $self = shift;
  209   my @input = @_;
  210 
  211   push( @{ $self->{extras} }, @input);
  212 
  213   #call as a method of $self
  214   &ChoiceList::choose_extra($self, scalar(@{ $self->{extras} }));
  215 }
  216 
  217 #This means rf_print_q is not used but still exists for user customization
  218 sub print_q {
  219   my $self = shift;
  220 
  221   @{ $self->{questions} }[0];
  222 }
  223 
  224 
  225 #This is called choose2 because it needs to be called internally
  226 #but i didn't want it available to the user (hence choose being
  227 #overloaded to give a error message above).
  228 sub choose2 {
  229   my $self = shift;
  230   my @input = @_;
  231 
  232   $self->getRandoms(scalar(@{ $self->{answers} }), @input);
  233   $self->selectQA();
  234 }
  235 
  236 sub selectQA {
  237   my $self = shift;
  238 
  239   $self->{selected_q} = $self->{questions};
  240   $self->{selected_a} = [ @{ $self->{answers} }[@{ $self->{shuffle} }] ];
  241   $self->{inverted_shuffle} = [ &ChoiceList::invert(@{ $self->{shuffle} }) ];
  242 }
  243 
  244 #Multiple
  245 sub ra_correct_ans {
  246   warn "Multiple does not use ra_correct_ans because radio_cmp and checkbox_cmp expect a string.\nYou should use correct_ans instead.";
  247 }
  248 
  249 #sends letters for comparison instead of actual answers
  250 #actual answers aren't used because they might contain LaTeX or HTML
  251 sub correct_ans {
  252   my $self = shift;
  253   my @ans = &ChoiceList::ALPHABET( sort { $a <=> $b } @{$self->{inverted_shuffle}} );
  254 
  255   #radio_cmp and checkbox_cmp expect a string, not a reference to an array like str_cmp, etc
  256   join "", @ans;
  257 }
  258 
  259 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9