--- loncom/homework/caparesponse/caparesponse.pm 2002/09/30 15:10:58 1.58
+++ loncom/homework/caparesponse/caparesponse.pm 2002/10/01 14:10:44 1.62
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# caparesponse definition
#
-# $Id: caparesponse.pm,v 1.58 2002/09/30 15:10:58 sakharuk Exp $
+# $Id: caparesponse.pm,v 1.62 2002/10/01 14:10:44 sakharuk Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -220,19 +220,36 @@ sub end_numericalresponse {
for ($ind=0;$ind<$number_of_bubbles;$ind++) {
$bubbles_values[$ind] = $answers[0]*$factor**($power-$powers[$powers_number-$ind-1]);
}
+ my @alphabet = ('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
+ 'Q','R','S','T','U','V','W','X','Y','Z');
if ($target eq 'web') {
$result.= '
';
for ($ind=0;$ind<$number_of_bubbles;$ind++) {
- my $ans = sprintf('%.'.$formats[0],$bubbles_values[$ind]);
- $result.=''.$ans.' | ';
+ my $ans;
+ if ($formats[0] ne '') {
+ $ans = sprintf('%.'.$formats[0],$bubbles_values[$ind]);
+ } else {
+ my $badans = $bubbles_values[$ind];
+ my $format = '';
+ #What is the number? (integer,decimal,floating point)
+ if ($badans=~/^(\d*\.?\d*)(E|e)(\d*)$/) {
+ $format = 'e'.$2;
+ } elsif ($badans=~/^(\d*)\.(\d*)$/) {
+ $format = '4f';
+ } elsif ($badans=~/^(\d*)$/) {
+ $format = 'd';
+ }
+ $ans = sprintf('%.'.$format,$bubbles_values[$ind]);
}
+ $result.=''.$alphabet[$ind].': '.$ans.' | ';
+ }
$result.='
';
} elsif ($target eq 'tex') {
- my @alphabet = ('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
- 'Q','R','S','T','U','V','W','X','Y','Z');
my $max_val = 0;
if ($formats[0]=~m/^(\d+)E([^\d]*)(\d*)$/) {
$max_val=$1+$2+4;
+ } else {
+ $max_val=5;
}
$max_val = int(90/(($max_val+6)*2));
my $celllength = 90/$max_val-12;
@@ -253,7 +270,22 @@ sub end_numericalresponse {
}
$result.='}\hline';
for ($ind=$cou;$ind<$cou+$table_range[$j];$ind++) {
- my $ans = sprintf('%.'.$formats[0],$bubbles_values[$ind]);
+ my $ans;
+ if ($formats[0] ne '') {
+ $ans = sprintf('%.'.$formats[0],$bubbles_values[$ind]);
+ } else {
+ my $badans = $bubbles_values[$ind];
+ my $format = '';
+ #What is the number? (integer,decimal,floating point)
+ if ($badans=~/^(\d*\.?\d*)(E|e)(\d*)$/) {
+ $format = 'e'.$2;
+ } elsif ($badans=~/^(\d*)\.(\d*)$/) {
+ $format = '4f';
+ } elsif ($badans=~/^(\d*)$/) {
+ $format = 'd';
+ }
+ $ans = sprintf('%.'.$format,$bubbles_values[$ind]);
+ }
$result.=' '.$alphabet[$ind].': & '.$ans.' ';
if ($ind != $cou+$table_range[$j]-1) {$result.=' & ';}
}
@@ -325,7 +357,7 @@ sub end_numericalresponse {
}
$result.=&Apache::response::answer_footer($$tagstack[-1]);
}
- &Apache::response::end_response;
+ &Apache::response::end_response;
return $result;
}