Matching list example | topic started 5/8/2000; 3:52:04 PM last post 9/10/2001; 9:02:51 PM |
|
|
|
9/10/2001; 9:02:51 PM (reads: 5734, responses: 0) |
|||||
'Matching list' basic example(for more advanced information on matching lists, see Match.pm)
(1 pt) rochesterLibrary/setMAAtutorial/matchinglistexample.pg
WARNINGS µ¦å{h <hr /> <pre>DOCUMENT(); # This should be the first executable line in the problem.<br /><br />loadMacros(<br /> "PGbasicmacros.pl",<br /> "PGchoicemacros.pl",<br /> "PGanswermacros.pl",<br /> );<br /><br /><br />TEXT(beginproblem(), $BR,$BBOLD, "Matching list example", $EBOLD, $BR,$BR);<br /><br /><br /># Since this is a matching question, we do not usually wish to tell students<br /># which parts of the matching question have been answered correctly and which<br /># areincorrect. That is too easy. To accomplish this we set the following<br /># flag to zero.<br />$showPartialCorrectAnswers = 0;<br /><br /># Make a new match list<br />$ml = new_match_list();<br /># enter questions and matching answers<br />$ml -> qa (<br />"\( \sin(x) \)", # Notice the use of the LateX construction<br />"\( \cos(x) \)", # for math mode: \( ... \) and the use of TeX<br />"\( \cos(x) \)", # symbols such as \sin and \tan.<br />"\( -\sin(x) \)",<br />"\( \tan(x) \)",<br />"\( \sec^2(x) \)", # Remember that in these strings we are <br /> # only specifying typography,via TeX,<br />"\( 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 {',<br /> HTML =>' ',<br /> Latex2HTML => ' '<br />);<br />$ESPACING = MODES(TeX => '}}', HTML =>'', Latex2HTML => ''); sub protect_enumerated_lists {<br /> my @in = @_;<br /> my @out = ();<br /> foreach my $item (@in) {<br /> push(@out, $BSPACING . $item . $ESPACING);<br /> } @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();
|