| 1 | |
1 | |
| 2 | #Construct for Multiple Choice. |
2 | #Construct for Multiple Choice. |
| 3 | #Inherits from List.pm |
3 | #Inherits from ChoiceList.pm |
| 4 | #VS 6/16/2000 |
4 | #VS 6/16/2000 |
| 5 | |
5 | |
| 6 | |
6 | |
| 7 | =head1 NAME |
7 | =head1 NAME |
| 8 | |
8 | |
| 9 | Multiple.pm -- sub-class of List that implements a multiple choice question. |
9 | Multiple.pm -- sub-class of ChoiceList that implements a multiple choice question. |
| 10 | |
10 | |
| 11 | All items accessed by $out=$mc->item($in); |
11 | All items accessed by $out=$mc->item($in); |
| 12 | |
12 | |
| 13 | =head1 SYNOPSIS |
13 | =head1 SYNOPSIS |
| 14 | |
14 | |
| … | |
… | |
| 185 | |
185 | |
| 186 | #use strict; |
186 | #use strict; |
| 187 | package Multiple; |
187 | package Multiple; |
| 188 | |
188 | |
| 189 | @Multiple::ISA = undef; |
189 | @Multiple::ISA = undef; |
| 190 | #require "${Global::mainDirectory}courseScripts/List.pm"; |
|
|
| 191 | @Multiple::ISA = qw( Exporter List ); |
190 | @Multiple::ISA = qw( Exporter ChoiceList ); |
| 192 | |
191 | |
| 193 | # *** Subroutines which overload List.pm *** |
192 | # *** Subroutines which overload ChoiceList.pm *** |
| 194 | sub choose { warn "Multiple choice does not support choosing answers.\n(You can't use \$mc->choose().)"; } |
193 | sub choose { warn "Multiple choice does not support choosing answers.\n(You can't use \$mc->choose().)"; } |
| 195 | sub choose_extra { warn "Multiple choice does not support choosing answers.\n(You can't use \$mc->choose_extra().)"; } |
194 | sub choose_extra { warn "Multiple choice does not support choosing answers.\n(You can't use \$mc->choose_extra().)"; } |
| 196 | sub extras { warn "Extras() is not a method of Multiple.pm.\nUse the extra() method to add extra answers."; } |
195 | sub extras { warn "Extras() is not a method of Multiple.pm.\nUse the extra() method to add extra answers."; } |
| 197 | |
196 | |
| 198 | sub qa { |
197 | sub qa { |
| … | |
… | |
| 210 | my @input = @_; |
209 | my @input = @_; |
| 211 | |
210 | |
| 212 | push( @{ $self->{extras} }, @input); |
211 | push( @{ $self->{extras} }, @input); |
| 213 | |
212 | |
| 214 | #call as a method of $self |
213 | #call as a method of $self |
| 215 | &List::choose_extra($self, scalar(@{ $self->{extras} })); |
214 | &ChoiceList::choose_extra($self, scalar(@{ $self->{extras} })); |
| 216 | } |
215 | } |
| 217 | |
216 | |
| 218 | #This means rf_print_q is not used but still exists for user customization |
217 | #This means rf_print_q is not used but still exists for user customization |
| 219 | sub print_q { |
218 | sub print_q { |
| 220 | my $self = shift; |
219 | my $self = shift; |
| … | |
… | |
| 237 | sub selectQA { |
236 | sub selectQA { |
| 238 | my $self = shift; |
237 | my $self = shift; |
| 239 | |
238 | |
| 240 | $self->{selected_q} = $self->{questions}; |
239 | $self->{selected_q} = $self->{questions}; |
| 241 | $self->{selected_a} = [ @{ $self->{answers} }[@{ $self->{shuffle} }] ]; |
240 | $self->{selected_a} = [ @{ $self->{answers} }[@{ $self->{shuffle} }] ]; |
| 242 | $self->{inverted_shuffle} = [ &List::invert(@{ $self->{shuffle} }) ]; |
241 | $self->{inverted_shuffle} = [ &ChoiceList::invert(@{ $self->{shuffle} }) ]; |
| 243 | } |
242 | } |
| 244 | |
243 | |
| 245 | #Multiple |
244 | #Multiple |
| 246 | sub ra_correct_ans { |
245 | sub ra_correct_ans { |
| 247 | warn "Multiple does not use ra_correct_ans because radio_cmp and checkbox_cmp expect a string.\nYou should use correct_ans instead."; |
246 | warn "Multiple does not use ra_correct_ans because radio_cmp and checkbox_cmp expect a string.\nYou should use correct_ans instead."; |
| … | |
… | |
| 249 | |
248 | |
| 250 | #sends letters for comparison instead of actual answers |
249 | #sends letters for comparison instead of actual answers |
| 251 | #actual answers aren't used because they might contain LaTeX or HTML |
250 | #actual answers aren't used because they might contain LaTeX or HTML |
| 252 | sub correct_ans { |
251 | sub correct_ans { |
| 253 | my $self = shift; |
252 | my $self = shift; |
| 254 | my @ans = &List::ALPHABET( sort { $a <=> $b } @{$self->{inverted_shuffle}} ); |
253 | my @ans = &ChoiceList::ALPHABET( sort { $a <=> $b } @{$self->{inverted_shuffle}} ); |
| 255 | |
254 | |
| 256 | #radio_cmp and checkbox_cmp expect a string, not a reference to an array like str_cmp, etc |
255 | #radio_cmp and checkbox_cmp expect a string, not a reference to an array like str_cmp, etc |
| 257 | join "", @ans; |
256 | join "", @ans; |
| 258 | } |
257 | } |
| 259 | |
258 | |