Matching Problem

Matching question template

Complete Code

Download file: Matching.pg

PG problem file

Explanation

DOCUMENT();

loadMacros(
    'PGstandard.pl',     'PGML.pl',
    'PGchoicemacros.pl', 'PGgraders.pl',
    'unionTables.pl',    'PGcourse.pl'
);

Preamble

The PGchoicemacros.pl macro is used to construct the list of multiple choice items, and the custom problem grader fluid from PGgraders.pl is used for incremental grading.

$showPartialCorrectAnswers = 0;

# Incremental grader
install_problem_grader(~~&custom_problem_grader_fluid);
$ENV{grader_numright} = [ 2,   4,   6 ];
$ENV{grader_scores}   = [ 0.3, 0.6, 1 ];
$ENV{grader_message} =
    'You can earn '
    . '30% partial credit for 2 - 3 correct answers, and '
    . '60% partial credit for 4 - 5 correct answers.';

# All or nothing grader
# install_problem_grader(~~&std_problem_grader);

# Create a matching list and use popups
$ml = new_match_list();
$ml->rf_print_q(~~&pop_up_list_print_q);
$ml->ra_pop_up_list([
    'No answer' => '?',
    'A'         => 'A',
    'B'         => 'B',
    'C'         => 'C',
    'D'         => 'D',
    'E'         => 'E',
    'F'         => 'F',
    'G'         => 'G',
    'H'         => 'H',
    'I'         => 'I',
]);

# Add correct questions and answers
$ml->qa(
    'Question a?',
    'Answer a',
    'Question b?',
    'Answer b',
    'Question c?',
    'Answer c',
    'Question d?',
    'Answer d',
    'Question e?',
    'Answer e',
    'Question f?',
    'Answer f',
);
$ml->choose(6);

# Add extra incorrect answers
$ml->extra('Extra answer 1', 'Extra answer 2',);
$ml->choose_extra(2);

$ml->makeLast('None of the above');

Setup

Withhold feedback when answers are submitted by setting $showPartialCorrectAnswers = 0;.

This problem uses an incremental grader called the custom_problem_grader_fluid. With this problem grader, the number of correct answers [2, 4, 6] and their corresponding scores [0.3, 0.6, 1] must be specified. The last entry in the grader_numright array must be the total number of questions asked, and the last entry in the grader_scores array must be 1 (otherwise nobody can earn full credit!). The grader message can also be customized by setting the value of grader_message to the desired custom message.

If a grader is desired that awards full credit when all questions are correct and no credit otherwise, use the commented out standard problem grader code instead.

Create a list of 6 questions and answers, 2 extra answers, and a ‘None of the above’ answer that will be made last with makeLast. So the popup list must have 9 entries A through I.

As an alternative, see Matching Problem (Alternate) for another way to write a matching problem.

BEGIN_PGML
Match each question with its answer.

[@ ColumnMatchTable($ml) @]***
END_PGML

Statement

The ColumnMatchTable() method is provided by the macro file unionTables.pl.

ANS(str_cmp($ml->ra_correct_ans));

Answer

This is used for answer checking.
@correct      = @{ $ml->ra_correct_ans() };
$answerstring = join(', ', @correct);

BEGIN_PGML_SOLUTION
The correct answers are [$answerstring].
END_PGML_SOLUTION

ENDDOCUMENT();

Solution

Extract the correct answers from the MatchList object and reformat.