parserOneOf.pl - Implements a MathObject that allows students to entery any one of several possible right answers.
This file implements a MathObject that allows the student to answer any one of several correct answers. The correct answer (when shown in the results table) will list all the possibilities.
To use it, load the macro file, and create a OneOf() object:
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"parserOneOf.pl",
);
$ans = OneOf(pi,"2x+1");
and create the answer checker as usual:
ANS($ans->cmp);
If the student answers either "pi" or "2x+1" (or answers equivalent to those), the answer will be marked correct.
You can control the format of the correct answer string using the following flags on the OneOf object:
separator => ", " The string to use for the separator between
choices in the correct answer string
or => " or " The string to use before the final choice
tex_separator => "\hbox{, }" The string to use for the separator between
choices for TeX output
tex_or => "\hbox{ or }" The string to use before the final choice in
TeX output strings
format => string or code An sprintf-style format string to be used to
format the choices, or a code reference to
a subroutine that accepts the entries as input
and returns the formatted string.
tex_format => string or code Same as format above, but for use in tex output.
You can set this using the with() method, or by setting the values explicitly. For example,
$ans = OneOf(pi,"2x+1",34)->with(separator=>"; ",tex_separator=>";\,");
or
$ans = OneOf(pi,"2x+1",34);
$ans->{separator} = "; ";
$ans->{tex_separator} = ";\, ";