Forum archive 2000-2006

Michael Gage - PGchoicemacros.pl

Michael Gage - PGchoicemacros.pl

by Arnold Pizer -
Number of replies: 0
inactiveTopicPGchoicemacros.pl topic started 5/22/2000; 9:51:32 PM
last post 6/7/2000; 10:35:55 AM
userMichael Gage - PGchoicemacros.pl  blueArrow
5/22/2000; 9:51:32 PM (reads: 4150, responses: 1)


NAME

PGchoicemacros.pl --- located in the courseScripts directory


SYNPOSIS

There are two types of choice macros. The older versions are simply scripts. The newer versions involve the "List.pm" class and its sub-classes and the use of objects based on these classes. The list sub-classes are: "Match.pm" which aids in setting up matching question and answer lists, "Select.pm" which aids in selecting and presenting a subset of questions with short answers (e.g. true/false questions) from a larger question set, and "Multiple.pm" which aids in setting up a standard style, one question, many answers type multiple choice question.


DESCRIPTION

Sample usage:

    $ml = new_match_list();
# enter three questions and their answers
$ml->qa( "What color is a rose?",
"Red",
"What color is the sky?",
"Blue",
"What color is the sea?",
"Green"
);
# choose two of these questions, ordered at random,
# which will be printed in the problem.
$ml->choose(2);
BEGIN_TEXT
Match the answers below with these questions:$BR
\\{$ml->print_q\\} $BR
Answers:
\\{$ml->print_a\\}
END_TEXT
    ANS( $ml->ra_correct_ans()  );

Matching List macros

new_match_list

Matching list object creation macro

Usage:

    $ml = new_match_list();

Which is short hand for the following direct call to Match

    $ml = new Match(random(1,2000,1), ~~&std_print_q, ~~&std_print_a);

Either call will create a matching list object in the variable $ml. ( Note: $ml cannot be a my variable if it is to be used within a BEGIN_TEXT/END_TEXT block.)

The first argument is the seed for the match list (choosen at random between 1 and 2000 in the example above.). The next two arguments are references to the print subroutines used to print the questions and the answers. Other printing methods can be used instead of the standard ones. An example of how to do this is demonstrated with "pop_up_list_print_q" below.

std_print_q

Standard method for formatting a list of questions with answer blanks.

This formatting routine is the default method for formatting the way questions are printed for each of the three sub-classes of "List.pm". It lists the questions vertically, numbering them sequentially and providing an answer blank before each question. std_print_q checks which mode the user is trying to print the questions from and returns the appropriately formatted string.

The length of the answer blank can be set with $ml-

To replace the standard question formatting method with your own, use:

    $ml->rf_print_q(~~&my_question_format_method)

Your method should be a subroutine of the form my_question_format_method($self, @questions) and should return a string to be printed. The @questions array contains the questions to be listed, while $self can be used to obtain extra information from the object for formatting purposes. The variable $main::displayMode contains the current display mode. (See "MODES" for more details on display modes and see "writing print methods for lists" for details on constructing formatting subroutines.)

std_print_a

Standard method for formatting a list of answers.

This simple formatting routine is the default method for formatting the answers for matching lists. It lists the answers vertically lettered sequentially.

To replace the standard answer formatting method with your own subroutine use:

    $ml->rf_print_q(~~&my_answer_format_method)

The answer formatting method has the same interface as the question formatting method.

Select List macros

new_select_list

Select list object creation macro

Usage:

    $sl = new_select_list;

Which is equivalent to this direct call to Select

    $sl = new Select(random(1,2000,1), ~~&std_print_q, ~~&std_print_a);

Either call will create a select list object in the variable $sl. ( Note that $sl cannot be a my variable if it is to be used within a BEGIN_TEXT/END_TEXT block.) The printing methods are the same as those defined for new_match_list above. See the documentation for "Select.pm" to see how to use this object to create a true/false question.

std_print_a is only intended to be used for debugging with select lists, as there is rarely a reason to print out the answers to a select list.

new_pop_up_select_list

Usage:

    $sl = new_pop_up_select_list;</I></PRE>

Which is equivalent to this direct call to Select

    $sl = new Select(random(1,2000,1), ~~&pop_up_list_print_q, ~~&std_print_a);

Either call will create a select list object in the variable $sl. ( Note that $sl cannot be a my variable if it is to be used within a BEGIN_TEXT/END_TEXT block.) The printing methods are passed as references (~~ in PG equals \ in perl) to subroutines so that no matter what printing subroutines are used, those subroutines can be used by saying $sl->print_q and $sl->print_a. This also means that other subroutines can be used instead of the default ones.

See the documentation for <a href='Select'>Select.pm</a> to see how to use this

object to create a true/false question.

std_print_q

Standard method for printing questions with answer boxes

See std_print_q under Matching Lists above.

pop_up_list_print_q

Alternate method for print questions with pop up lists.

Usage:

This printing routine is used to print the questions for a true/false or other select list with a preceding pop up list of possible answers. A list of values and labels need to be given to the pop_up_list so that the intended answer is returned when a student selects an answer form the list. Notethe use of => to associate the values on the left with the labels on the right, this means that, for instance, the student will see the word True in the pop_up_list but the answer that is returned to the grader is T, so that it corresponds with what the professor typed in as the answer when using $sl->qa('blah blah', 'T');

    $sl->ra_pop_up_list([value => label,
T => 'True',
F => 'False']);

std_print_a

This is only intended to be used for debugging as there is rarely a reason to print out the answers to a select list.

See std_print_a under Matching Lists above.

Multiple Choice macros

new_multiple_choice

Multiple choice object creation macro

Usage:

    $mc = new_multiple_choice;

Which is equivalent to this direct call to Multiple

    $mc = new Multiple(random(1,2000,1), ~~&std_print_q, ~~&std_print_a);

Either call will create a multiple choice object in the variable $mc. Note that $mc cannot be a my variable if it is to be used within a BEGIN_TEXT/END_TEXT block.

See the documentation for Multiple.pm to see how to use this object to create a multiple choice question.

std_print_q

Standard method for printing questions

See std_print_q under Matching Lists above.

radio_print_a

Method for printing answers with radio buttons

This simple printing routine is used to print the answers to multiple choice questions in a bulleted style with radio buttons preceding each possible answer. When a multiple choice object is created, a reference to radio_print_a is passed to that object so that it can be used from within the object later.

radio_print_a checks which mode the user is trying to print the answers from and returns the appropriately formatted string.

new_checkbox_multiple_choice

Checkbox multiple choice object creation macro

Usage:

    $cmc = new_checkbox_multiple_choice;

Which is equivalent to this direct call to Multiple

    $cmc = new Multiple(random(1,2000,1), ~~&std_print_q, ~~&checkbox_print_a);

Either call will create a checkbox multiple choice object in the variable $cmc. Note that $cmc cannot be a my variable if it is to be used within a BEGIN_TEXT/END_TEXT block.

See the documentation for Multiple.pm to see how to use this object to create a multiple choice question.

std_print_q

Standard method for printing questions

See std_print_q under Matching Lists above.

checkbox_print_a

Method for printing answers with radio buttons

This simple printing routine is used to print the answers to multiple choice questions in a bulleted style with checkboxes preceding each possible answer. When a multiple choice object is created, a reference to checkbox_print_a is passed to that object so that it can be used from within the object later.

checkbox_print_a checks which mode the user is trying to print the answers from and returns the appropriately formatted string.

new_match_list

    Usage: $ml = new_match_list();

Note that $ml cannot be a my variable if used within a BEGIN_TEXT/END_TEXT block

new_select_list sage: $sl = new_select_list();

Note that $sl cannot be a my variable if used within a BEGIN_TEXT/END_TEXT block

new_pop_up_select_list;

    Usage: $pusl = new_pop_up_select_list();

new_multiple_choice

    Usage: $mc = new_multiple_choice();

new_checkbox_multiple_choice

    Usage: $mcc = new_checkbox_multiple_choice();

initializing a pop_up_list

    Usage:  $sl->rf_print_a(~~&pop_up_list_print_q);
$sl->ra_pop_up_list([</I>value<I> => </I>label<I>, T => 'True', F =>
'False']);

legacy macros

These are maintained for backward compatibility. They can still be useful in constructing non-standard lists that don't fit the various list objects. In general the using the list objects is likely to give better results and is preferred.

qa

invert

NchooseK

shuffle

match_questions_list

File path = /ww/webwork/pg/macros/PGchoicemacros.pl

<| Post or View Comments |>


userTori Sweetser - new modules  blueArrow
6/7/2000; 10:35:55 AM (reads: 2849, responses: 0)
We need to add documentation somewhere for adding new modules.

-Tori

<| Post or View Comments |>