µ¦å{h
HomeCurrent UR coursesVisitor pageIntro to WeBWorKWeBWorK 2 TwikiWW CommunityGrant Support & awardsDiscussion groupProblem libraryWrite/modify problemsCreate & manage courseTutorial on running a courseHowTosFAQWeBWorK2 FAQSoftware DownloadHow to Install WW serverFeedbackSite MapChange preferencesChange password
|
'Matching list' basic example(for more advanced information on matching lists, see Match.pm) To obtain the problem:
WARNINGS µ¦å{h
##DESCRIPTION
##KEYWORDS('sample')
## Tagged by jjh2b
## DBsubject('WeBWorK')
## DBchapter('WeBWorK Tutorial')
## DBsection('MAA Tutorial')
## Date('8/30/07')
## Author('')
## Institution('')
## TitleText1('')
## EditionText1('')
## AuthorText1('')
## Section1('')
## Problem1('')
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();
|
||
Last update: Monday, March 18, 2002 at 1:46:19 PM.
This site maintained using Manila and Frontier software. |
|||