ChoiceList.pm -- super-class for all ChoiceList structures

From WeBWorK

Jump to: navigation


NAME

        ChoiceList.pm  -- super-class for all ChoiceList structures

SYNOPSIS

ChoiceList.pm is not intended to be used as a stand alone object.

It is a super-class designed to be inherited by sub-classes that, through small changes, can be used for a variety of different questions that involve some sort of list of questions and/or answers.

ChoiceList.pm has been used to construct Match.pm, Select.pm, and Multiple.pm.

These three classes are objects that can be used to create the following question types:

Matching list: Given a list of questions and answers, match the correct answers to the questions. Some answers may be used more than once and some may not be used at all. The order of the answers is usually random but some answers can be appended to the end in a set order (i.e. 'None of the above'). Answers are given corresponding letters as shortcuts to typing in the full answer. (i.e. the answer to #1 is A).

Select list: Given a list of questions and (usually) implied answers, give the correct answer to each question. This is intended mainly for true/false questions or other types of questions where the answers are short and can therefore be typed in by the user easily. If a select list is desired but the answers are too long to really type in, a popup-list of the answers can be used.

Multiple choice: Given a single question and a list of answers, select the single correct answer. This structure creates a standard multiple choice question as would be seen on a standardize test. Extra answers are entered along with the question in a simple format and (as with Match.pm), if necessary, can be appended in order at the end (i.e. 'None of the above')

See Match.pm, Select.pm, Multiple.pm, and PGchoicemacros.pl

DESCRIPTION

Variables and methods available to sub-classes

Variables

        questions                               # array of questions as entered using qa()
        answers                                 # array of answers as entered using qa()
        extras                                  # array of extras as entered using extra()
        selected_q                              # randomly selected subset of "questions"
        selected_a                              # the answers for the selected questions
        selected_e                              # randomly selected subset of "extras"
        ans_rule_len                    # determines the length of the answer blanks
                                                        # default is 4
        slice                                   # index used to select specific questions
        shuffle                                 # permutation array which can be applied to slice
                                                        # to shuffle the answers
        inverted_shuffle                # the inverse permutation array
        rf_print_q                              # reference to any subroutine which should
                                                        # take ($self, @questions) as parameters and
                                                        # output the questions in a formatted string.
                                                        # If you want to change the way questions are
                                                        # printed, write your own print method and set
                                                        # this equal to a reference to to that method
                                                        # (i.e. $sl->rf_print_q = ~~&printing_routine_q)
        rf_print_a                              # reference to any subroutine which should
                                                        # take ($self, @answers) as parameters and
                                                        # output the answers in a formatted string.
                                                        # If you want to change the way answers are
                                                        # printed, write your own print method and set
                                                        # this equal to a reference to to that method
                                                        # (i.e. $sl->rf_print_a = ~~&printing_routine_a)
        ra_pop_up_list              # Field used in sub classes that use pop_up_list_print_q
                                                        # to format the questions. (Placing a pop_up_list next to
                                                        # each question instead of an answer blank.
                                                        # It is initialized to
                                                        # => [no_answer =>'  ?', T => 'True', F => 'False']
        ans_rule_len                    # field which can be used in the question printing routines
                                                        # to determine the length of the answer blanks before the questions.

Methods

        qa( array )                             # accepts an array of strings which can be used
                                                        # for questions and answers
        extra( array )                  # accepts an array of strings which can be used
                                                        # as extra answers
        print_q                                 # yields a formatted string of question to be
                                                        # matched with answer blanks
        print_a                                 # yields a formatted string of answers
        choose([3, 4], 1)               # chooses questions indexed 3 and 4 and one other
                                                        # randomly
        choose_extra([3, 4], 1) # choooses extra answers indexed 3 and 4 and one
                                                        # other
        makeLast( array )               # accepts an array of strings (like qa) which will
                                                        # be forced to the end of the list of answers.
        ra_correct_ans                  # outputs a reference to the array of correct answers
        correct_ans                             # outputs a concatenated string of correct answers (only for Multiple)

Usage

        None -- see SYNOPSIS above

qa Usage: $ml->qa( qw( question1 answer1 question2 answer2 ) );


=cut

sub qa {
my $self = shift;
my @questANDanswer = @_;

        while (@questANDanswer) {
                push (@{ $self->{questions} }, shift(@questANDanswer) );
                push (@{ $self->{answers} },   shift(@questANDanswer) );
        }
}

#Input extra answers -- not to be confused with access method extras below sub extra { my $self = shift; push(@{ $self->{extras} }, @_); #pushing allows multiple calls without overwriting old "extras" }

#Output questions #Doesn't do actual output, refers to method given in call to 'new' (rf_print_q)

sub print_q {
my $self = shift;

        &{ $self->{rf_print_q} }( $self, @{ $self->{selected_q} } );
}

#Output answers #Doesn't do actual output, refers to method given in call to 'new' (rf_print_a) sub print_a { my $self = shift;

        &{ $self->{rf_print_a} }( $self, @{ $self->{selected_a} } );
}

#return array of answers to be checked against the students answers #defaults to returning the actual selected answers (should be overloaded for other types of answers) sub ra_correct_ans { my $self = shift; return $self->{selected_a}; }

cmp

        Usage    ANS($ml -> cmp);
        
provides a MathObject like comparison method
returns a string of comparison methods for checking the list object