'Matching list' basic example
(for more advanced information on matching lists, see Match.pm) (1 pt) rochesterLibrary/setMAAtutorial/matchinglistexample.pg
Matching list example
Place the letter of the derivative next to each function listed below:
1. 2. 3. 4.
A. B. C. D.
Let's print the questions again, but insist that the
first two questions (about sin and cos) always be included.
Here is a second way to format this question, using tables:
And below is yet another way to enter a table of questions and answers:
|
WARNINGS µ¦å{h
DOCUMENT(); # This should be the first executable line in the problem.
loadMacros( "PGbasicmacros.pl", "PGchoicemacros.pl", "PGanswermacros.pl", );
TEXT(beginproblem(), $BR,$BBOLD, "Matching list example", $EBOLD, $BR,$BR);
# Since this is a matching question, we do not usually wish to tell students # which parts of the matching question have been answered correctly and which # areincorrect. That is too easy. To accomplish this we set the following # flag to zero. $showPartialCorrectAnswers = 0;
# Make a new match list $ml = new_match_list(); # enter questions and matching answers $ml -> qa ( "\( \sin(x) \)", # Notice the use of the LateX construction "\( \cos(x) \)", # for math mode: \( ... \) and the use of TeX "\( \cos(x) \)", # symbols such as \sin and \tan. "\( -\sin(x) \)", "\( \tan(x) \)", "\( \sec^2(x) \)", # Remember that in these strings we are # only specifying typography,via TeX, "\( x^{20} \)", #not any calculational rules. "\( 20x^{19} \)", "\( \sin(2x) \)", "\( 2\cos(2x) \)", "\( \sin(3x) \)", "\( 3\cos(3x) \)" );
# Calculate coefficients for another question $b=random(2,5); $exp= random(2,5); $coeff=$b*$exp; $new_exp = $exp-1;
# Store the question and answers in the match list object. $ml -> qa ( '\( ${b}x^$exp \)', '\( ${coeff}x^{$new_exp} \)', );
# Add another example $b2=random(2,5); $exp2= random(2,5); $coeff2=$b2*$exp; $new_exp2 = $exp-1; $ml -> qa ( "\( ${b2}x^$exp2 \)", "\( ${coeff2}x^{$new_exp2} \)", );
# Choose four of the question and answer pairs at random. $ml ->choose(4); # Using choose(8) would choose all eight questions, # but the order of the questions and answers would be # scrambled.
# The following code is needed to make the enumeration work right within tables # when LaTeX output is being used. # It is an example of the powerful tools of TeX and perl which are available # for each PG problem author. # Once we figure out the best way to protect enumerated lists automatically # we will include it in the tables macro. Meantime, it is better to have # have to do it by hand, rather than to have the wrong thing done automatically.
$BSPACING = MODES( TeX => '\hbox to .5\linewidth {\hspace{0.5cm}\vbox {', HTML =>' ', Latex2HTML => ' ' ); $ESPACING = MODES(TeX => '}}', HTML =>'', Latex2HTML => ''); sub protect_enumerated_lists { my @in = @_; my @out = (); foreach my $item (@in) { push(@out, $BSPACING . $item . $ESPACING); } @out; } # End of code for protecting enumerated lists in TeX.
# Now print the text using $ml->print_q for # the questions and $ml->print_a to print the answers.
BEGIN_TEXT $PAR
Place the letter of the derivative next to each function listed below: $BR \{ $ml -> print_q \} $PAR \{$ml -> print_a \} $PAR END_TEXT
ANS(str_cmp( $ml->ra_correct_ans ) ) ; # insist that the first two questions (labeled 0 and 1) are always included $ml ->choose([0,1],1); BEGIN_TEXT Let's print the questions again, but insist that the first two questions (about sin and cos) always be included. Here is a second way to format this question, using tables: $PAR \{begintable(2)\} \{row(protect_enumerated_lists( $ml->print_q, $ml -> print_a) )\} \{endtable()\} $PAR And below is yet another way to enter a table of questions and answers: $PAR END_TEXT ANS(str_cmp( $ml->ra_correct_ans ) ) ; # Finally add a last answer $ml ->makeLast("The derivative is $BR not provided"); BEGIN_TEXT \{ begintable(2) \} \{ row( protect_enumerated_lists($ml->print_q, $ml ->print_a))\} \{endtable()\} END_TEXT # Enter the correct answers to be checked against the answers to the students. ANS(str_cmp( $ml->ra_correct_ans ) ) ;
ENDDOCUMENT();
- Since this is a matching
questions, we do not usually wish to tell students which parts of the
matching question have been answered correctly and which are incorrect.
That is too easy. To accomplish this we set the following flag
$showPartialCorrectAnswers to 0 (line 15).
- Saying that
$ml $ml
is a scalar variable which contains a pointer to the match list object,
but you can think of the match list object as being shoe horned into
the variable $ml . You need to remember that $ml
Some people use the convention $o_ml to remind them that the variable
contains an object, but for short problems that is probably not
necessary. An object contains both data (in this case the list of
questions and answers) and subroutines (called methods) for
manipulating that data. - The construction
$ml ->qa( ..list of alternating questions and matching answers ...). Asks the object $ml
to store the matching questions and answers given in the argument in
its private data (lines 44 to 58, 69.. and 78..). Note that that you
can call qa() more than once with a match list and it
will add new questions. This is not true with all objects. Some objects
will overwrite previous questions if qa() is used more than once.
- The construction
$ml->choose(4) asks the object to choose three question/answer pairs from its private data and
-
$out = $ml->print_q() asks the object to store a string of the formatted questions in the variable $out . Calling \{ $ml->print_q() \} within BEGIN_TEXT / END_TEXT statements will just append the formatted questions to the ouput text that the student sees (line 119).
-
$out = $ml->print_a() asks the object to store a string of the formatted answers in the variable $out . \{ $ml->print_a() \} can be used just like above to append a string of the formatted answers to the output text seen by the student (line 121).
-
ANS is needed to compare the students answers to the correct answers (line 146).
- The answer evaluator
str_cmp
is just one of many possible answer evaluators from which to choose,
each of which specifies a different method for comparing the correct
answers to the students answers. str_cmp is almost always
used with matching lists since the correct answers will always be a
letter indicating one of the possible answers (line 146).
<| Post or View Comments |>
|