File:  [LON-CAPA] / loncom / homework / default_homework.lcpm
Revision 1.8: download - view: text, annotated - select for diffs
Mon Oct 30 20:24:38 2000 UTC (23 years, 6 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- caparesponse_check properly looks for the type of response

    1: # file name (temp): default_homework 
    2: # used by lonxml::xmlparse() as input variable $safeinit to Apache::run::run()
    3: # 
    4: #
    5: $RANDOMINIT=0;
    6: 
    7: sub caparesponse_check {
    8:   my $answer='';
    9:   my $type='';
   10:   my $tol_type='';
   11:   my $tolerance='';
   12:   my $sig_lbound='';
   13:   my $sig_ubound='';
   14:   my $ans_fmt='';
   15:   my $unit_str='';
   16:   my $calc='';
   17:   my ($response,$expr)=@_;
   18:   
   19:   ($answer,$type,$tol_type,$tolerance,$sig_lbound,$sig_ubound,$ans_fmt,
   20:    $unit_str,$calc) = eval $expr.'return $answer,$type,$tol_type,$tolerance,$sig_lbound,$sig_ubound,$ans_fmt,$unit_str,$calc';
   21: 
   22:   #type's definitons come from capaParser.h
   23:   if ($type eq '' ) {
   24:     if ( $answer eq ($answer *1.0)) { $type = 2;
   25:     } else { $type = 3; }
   26:   } else {
   27:          if ($type eq 'cs')    { $type = 4;
   28:     } elsif ($type eq 'ci')    { $type = 3;
   29:     } elsif ($type eq 'mc')    { $type = 5;
   30:     } elsif ($type eq 'fml')   { $type = 8;
   31:     } elsif ($type eq 'subj')  { $type = 7;}
   32:   }
   33: 
   34:   
   35:   my $result = &caparesponse_capa_check_answer($response,$answer,$type,
   36: 					       $tol_type,$tolerance,
   37: 					       $sig_lbound,$sig_ubound,
   38: 					       $ans_fmt, $unit_str,$calc);
   39:   return ":$result:$response:$answer:";
   40: }
   41: 
   42: sub tex {
   43:   if ( $external::target eq "tex" ) {
   44:     #$SCRIPT_RESULT.=@_[0];
   45:     return @_[0];
   46:   } else {
   47:     #$SCRIPT_RESULT.=@_[1];
   48:     return @_[1];
   49:   }
   50: }
   51: 
   52: sub web {
   53:   if ( $external::target eq "tex" ) {
   54:     #$SCRIPT_RESULT.=@_[1];
   55:     return @_[1];
   56:   } else {
   57:     if ( $external::target eq "web") {
   58:       #$SCRIPT_RESULT.=@_[0];
   59:       return @_[0];
   60:     } else {
   61:       #$SCRIPT_RESULT.=@_[2];
   62:       return @_[2];
   63:     }
   64:   }
   65: }
   66: 
   67: sub problem {
   68:   $SCRIPT_RESULT.='1';
   69:   return '';
   70: }
   71: 
   72: sub hinton {
   73:   return 0;
   74: }
   75: 
   76: sub random {
   77:   my ($start,$end,$step)=@_;
   78:   if ( ! $RANDOMINIT ) { srand($external::randomseed); $RANDOMINIT=1; }
   79:   my $num=1+int(($end-$start)/$step);
   80:   my $result=$start + int(rand() * $num)*$step;
   81:   return $result;
   82: }
   83: 
   84: sub tan  { sin($_[0]) / cos($_[0]) }
   85: sub acos { atan2(sqrt(1 - $_[0] * $_[0]), $_[0] ); }
   86: sub asin { atan2($_[0], sqrt(1- $_[0] * $_[0]) );  }
   87: 
   88: sub html {
   89:   if ( $external::target eq "web" ) {
   90:     #$SCRIPT_RESULT.=@_[0];
   91:     return @_[0];
   92:   }
   93: }
   94: 
   95: 
   96: sub pow   {return $_[0] ** $_[1]; }
   97: sub ceil  {return (($_[0]-int($_[0]))== 0.0) ? $_[0] : (int($_[0])+ 1); }
   98: sub floor {return int($_[0]);  }
   99: 
  100: sub format {
  101:   my ($value,$fmt)=@_;
  102:   $SCRIPT_RESULT.=sprintf('%.'.$fmt,$value);
  103: }
  104: 
  105: sub map {
  106:   my $num = $#_/2;
  107:   my $i;
  108:   my @used;
  109:   my @permutation;
  110:   for ($i=0; $i < $num;) {
  111:     $rand = &random(1,$num,1);
  112:     if ( $used[$rand] == '0' ) {
  113:       $i++;
  114:       $used[$rand]='1';
  115:       $permutation[$i]=$rand;
  116:     }
  117:   }
  118:   for ( $i=1 ; $i<$num+1 ; $i++ ) {
  119:     ${$_[$permutation[$i]]}=$_[$i+$num]
  120:   }
  121: }
  122: 
  123: sub choose {
  124:   my $num = $_[0];
  125:   return $_[$num];
  126: }
  127: #$external::randomseed=time;
  128: #$a=2;
  129: #$b=2;
  130: #$c=2;
  131: #&map(1,\$a,\$b,\$c,3,4,5);
  132: #print $a."\n".$b."\n";

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>