next up previous contents
Next: Example Up: WeBWorK Newbie Guide - Previous: Matching Problems   Contents

Matching Problems -- via objects

In this section, we give an example of the newer way of producing matching questions. This method is probably easier to use than the scripts of the previous section, but that's since more of the underlying structure is hidden from the person writing the problem. On the other hand, since the object (no pun intended) is to be able to write these problems as efficiently as possible, the user may be willing to tolerate more of a black box. Parties interested in deeper understanding should read the code in Match.pm and Select.pm in the courseScripts directory.

The core of the problem is reduced to six statements. We discuss them briefly here, and then you can refer to the example below for more detail on their use.

## First create a new matched list object (and a pointer to it)
$matched_list_ptr = new_match_list();

## Generate the mathched list, by adding question-answer pairs to the list
$matched_list_ptr -> qa (  ... );

## Choose $k of the pairs to present (1 <= $k <= number of pairs)
$matched_list_ptr -> choose($k);

## From within a BEGIN_TEXT .. END_TEXT environment, print the questions
\{ $matched_list_ptr -> print_q \}

## From within a BEGIN_TEXT .. END_TEXT environment, print the answers
\{ $matched_list_ptr -> print_a \}

## Set up the answer string
ANS( str_cmp( $matched_list_ptr->ra_correct_ans ) ) ;



Subsections

Thomas R. Shemanske 2002-03-05