[LON-CAPA-cvs] cvs: loncom /homework/caparesponse caparesponse.pm

sakharuk lon-capa-cvs@mail.lon-capa.org
Thu, 17 Oct 2002 14:40:58 -0000


sakharuk		Thu Oct 17 10:40:58 2002 EDT

  Modified files:              
    /loncom/homework/caparesponse	caparesponse.pm 
  Log:
  For the exam 1. correctly adjust the size of bubbles to the text width;
  2. use correct enumeration through the environment variable; Working on units
  (almost done).
  
  
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.65 loncom/homework/caparesponse/caparesponse.pm:1.66
--- loncom/homework/caparesponse/caparesponse.pm:1.65	Mon Oct 14 16:37:27 2002
+++ loncom/homework/caparesponse/caparesponse.pm	Thu Oct 17 10:40:58 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # caparesponse definition
 #
-# $Id: caparesponse.pm,v 1.65 2002/10/14 20:37:27 albertel Exp $
+# $Id: caparesponse.pm,v 1.66 2002/10/17 14:40:58 sakharuk Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -249,10 +249,10 @@
 	    if ($formats[0]=~m/^(\d+)E([^\d]*)(\d*)$/) {
 		$max_val=$1+$2+4;
 	    } else {
-		$max_val=5;
+		$max_val=4;
 	    }
-	    $max_val = int(90/(($max_val+6)*2));
-            my $celllength = 90/$max_val-12;
+	    $max_val = int(0.9*$ENV{'form.textwidth'}/(($max_val+6)*2));
+            my $celllength = 0.9*$ENV{'form.textwidth'}/$max_val-10;
 	    my @table_range = ();
 	    my $number_of_tables = int($number_of_bubbles/$max_val);
 	    for (my $i=0;$i<$number_of_tables;$i++) {push @table_range,$max_val;}
@@ -262,17 +262,24 @@
 	    }
 	    my $j=0;
 	    my $cou=0;
-	    $result.='\vskip 2 mm \noindent ';
+	    $result.='\vskip -1 mm \noindent \begin{enumerate}\item[\textbf{'.$Apache::lonxml::counter.'}.]';
 	    for (my $i=0;$i<$number_of_tables;$i++) {
-		$result.='\vskip 0 mm \noindent \begin{tabular}{|';
+		$result.='\vskip -1 mm \noindent \begin{tabular}{';
 		for ($ind=0;$ind<$table_range[$j];$ind++) {
-		    $result.='lp{'.$celllength.' mm}|';
+		    $result.='lp{'.$celllength.' mm}';
 		}
-		$result.='}\hline';
+		$result.='}';
 		for ($ind=$cou;$ind<$cou+$table_range[$j];$ind++) {
 		    my $ans;
 		    if ($formats[0] ne '') {
 			$ans = sprintf('%.'.$formats[0],$bubbles_values[$ind]);
+			if ($ans =~ m/([0-9\.\-\+]+)E([0-9\-\+]+)/ ) {
+			    my $number = $1;
+			    my $power = $2;
+			    $power=~s/^\+//;
+			    $power=~s/^(-?)0+(\d+)//;
+			    $ans=$number.'$\times 10^{'.$1.$2.'}$';
+			} 
 		    } else {
 			my $badans = $bubbles_values[$ind];
 			my $format = ''; 
@@ -284,15 +291,27 @@
 			} elsif ($badans=~/^(\d*)$/) {
 			    $format = 'd';
 			}
-			$ans = sprintf('%.'.$format,$bubbles_values[$ind]);
+			$ans = sprintf('%.'.$format,$bubbles_values[$ind]);			
+			if ($ans =~ m/([0-9\.\-\+]+)E([0-9\-\+]+)/ ) {
+			    my $number = $1;
+			    my $power = $2;
+			    $power=~s/^\+//;
+			    $power=~s/^(-?)0+(\d+)//;
+			    $ans=$number.'$\times 10^{'.$1.$2.'}$';
+			} 
 		    }
-		    $result.=' '.$alphabet[$ind].': & '.$ans.' ';
+		    $result.='\hskip -3 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -2 mm & {\small '.$ans.'} ';
 		    if ($ind != $cou+$table_range[$j]-1) {$result.=' & ';}
 		}
 		$cou += $table_range[$j];
 		$j++;
-		$result.='\\\\\hline\end{tabular}\vskip 0 mm ';
-	    }	    
+		$result.='\\\\\end{tabular}\vskip 0 mm ';    
+	    }
+	    $result.='\end{enumerate}';
+	    $Apache::lonxml::counter++;		    
+	    my %moreenv;
+	    $moreenv{'form.counter'}=$Apache::lonxml::counter;
+	    &Apache::lonnet::appenv(%moreenv);   
 	}
     }
   } elsif ($target eq 'edit') {