PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : [ Application ] Math


pate33
28.01.2002, 14:37
Hi,

hab grad nix zu tun im geschaeft und wollt mal wieder meine kopfrechenkuenste etwas aufbessern... *g*

naja, ich hab mal diese kleine applikation geschrieben, mit welcher man ein wenig trainieren kann... :D

einfach copy & paste uebernehmen... ich ´freeware´... *gg* ... die datei sollte ´math.php´ heissen...

greetz

(fixed version (by cyrus)) leider ohne farbige tags, da mit der php funktion die br tags nicht dargestellt werden... :(


<?php

// startpage

if( empty( $action ) ) {
echo( &quot;<a href=\&quot;./math.php?action=small\&quot;>Kleines 1x1</a>

<a href=\&quot;./math.php?action=large\&quot;>Großes 1x1</a>&quot; );
$trueresult = 0;
$falseresult = 0;
$abs_start = date( &acute;i&acute;, time() );
}

// multiply firstvalue with secondvalue

elseif( $action == &acute;result&acute; ) {
$end_time = microtime();
$dauertmp = explode(&quot; &quot;, $end_time);
$end_time = $dauertmp[0] + $dauertmp[1];
$dauer = $end_time - $start_time;
$exec_time = substr($dauer, 0, 5);
$number = $firstvalue * $secondvalue;
if( $number == $result ) {
$resultstr = &quot;TRUE&quot;;
$trueresult++;
}
else {
$resultstr = &quot;FALSE - Result is: $number !&quot;;
$falseresult++;
}

if ($type == small) {
get_small_values( $resultstr, $firstvalue, $secondvalue, $exec_time, $trueresult, $falseresult );
} else {
get_large_values( $resultstr, $firstvalue, $secondvalue, $exec_time, $trueresult, $falseresult );
}

}

elseif( $action == &acute;small&acute; )
get_small_values( $resultstr, $firstvalue, $secondvalue, $exec_time, $trueresult, $falseresult );
elseif( $action == &acute;large&acute; )
get_large_values( $resultstr, $firstvalue, $secondvalue, $exec_time, $trueresult, $falseresult );
elseif( $action == &acute;endmath&acute; ) {
$abs_end = date( &acute;i&acute;, time() );
$abs_exec = $abs_end - $abs_start;
$abs_exec = getdate($abs_exec);

if($trueresult == &acute;&acute;) { $trueresult = 0; }
if($falseresult == &acute;&acute;) { $falseresult = 0; }

echo( &quot;<b>Statistics</b>
time of training: $abs_exec[minutes] min. and $abs_exec[seconds] sec.
<br><br>right answers: $trueresult
<br>wrong answers: $falseresult<br><br>
<a href=\&quot;./math.php\&quot;>replay</a>
&quot; );
}



function get_small_values( $resultstr, $firstvaluelast, $secondvaluelast, $exec_time, $trueresult, $falseresult ) {
if( !empty( $resultstr ) ) {
echo( &quot;last execution time : $exec_time sec.
last operation : $firstvaluelast x $secondvaluelast
last operation : <b>$resultstr</b>

&quot; );
}
$start_time = microtime();
$dauertmp = explode(&quot; &quot;, $start_time);
$start_time = $dauertmp[0] + $dauertmp[1];

$action = &quot;small&quot;;
$firstvalue = random( $action );
$secondvalue = random( $action );
echo( &quot;<b>Kleines 1x1</b>

<b>$firstvalue x $secondvalue = </b>
<form action=\&quot;./math.php?action=result&type=small&start_time=$start_time&result=$result&firstvalue=$firstvalue&secondvalue=$secondvalue\&quot; method=\&quot;post\&quot;>
<input type=\&quot;text\&quot; name=\&quot;result\&quot; size=\&quot;4\&quot; maxlength=\&quot;4\&quot;>
<input type=\&quot;hidden\&quot; name=\&quot;trueresult\&quot; value=\&quot;$trueresult\&quot; size=\&quot;4\&quot; maxlength=\&quot;4\&quot;>
<input type=\&quot;hidden\&quot; name=\&quot;falseresult\&quot; value=\&quot;$falseresult\&quot; size=\&quot;4\&quot; maxlength=\&quot;4\&quot;>
<input type=\&quot;submit\&quot; name=\&quot;submit\&quot; value=\&quot;submit\&quot;>
</form>
<a href=\&quot;./math.php?action=endmath&trueresult=$trueresult&falseresult=$falseresult\&quot;>End</a>
&quot;);

}



function get_large_values( $resultstr, $firstvaluelast, $secondvaluelast, $exec_time, $trueresult, $falseresult ) {
if( !empty( $resultstr ) ) {
echo( &quot;last execution time : $exec_time sec.
last operation : $firstvaluelast x $secondvaluelast
last operation : <b>$resultstr</b>
&quot; );
}
$start_time = microtime();
$dauertmp = explode(&quot; &quot;, $start_time);
$start_time = $dauertmp[0] + $dauertmp[1];


$action = &quot;large&quot;;
$firstvalue = random( $action );
$secondvalue = random( $action );
echo( &quot;<b>Großes 1x1</b>


<b>$firstvalue x $secondvalue = </b>
<form action=\&quot;./math.php?action=result&type=large&start_time=$start_time&result=$result&firstvalue=$firstvalue&secondvalue=$secondvalue\&quot; method=\&quot;post\&quot;>
<input type=\&quot;text\&quot; name=\&quot;result\&quot; size=\&quot;4\&quot; maxlength=\&quot;4\&quot;>
<input type=\&quot;submit\&quot; name=\&quot;submit\&quot; value=\&quot;submit\&quot;>
<input type=\&quot;hidden\&quot; name=\&quot;trueresult\&quot; value=\&quot;$trueresult\&quot; size=\&quot;4\&quot; maxlength=\&quot;4\&quot;>
<input type=\&quot;hidden\&quot; name=\&quot;falseresult\&quot; value=\&quot;$falseresult\&quot; size=\&quot;4\&quot; maxlength=\&quot;4\&quot;>
</form>

<a href=\&quot;./math.php?action=endmath&trueresult=$trueresult&falseresult=$falseresult\&quot;>End</a>

&quot;);
}

// get random integer

function random( $action ) {

if( $action == &quot;small&quot; ) {
mt_srand((double)microtime()*1000000);
return mt_rand( 1, 9 );
}

elseif( $action == &quot;large&quot; ) {
mt_srand((double)microtime()*1000000);
return mt_rand( 1, 19 );
}
}

?>


viel spass damit.


pate33
28.01.2002, 15:00
was mich nun dabei interessieren wuerde:

wie schreib ich sowas &acute;objekt orientiert&acute; ?

will das mal an nem praktischen beispiel ueben... :D

cYrus
28.01.2002, 15:22
so hab dann mal bisschen gebugfixed :D

<?php

// startpage

if( empty( $action ) ) {
echo( &quot;<a href=\&quot;./math.php?action=small\&quot;>Kleines 1x1</a>

<a href=\&quot;./math.php?action=large\&quot;>Großes 1x1</a>&quot; );
$trueresult = 0;
$falseresult = 0;
$abs_start = date( &acute;i&acute;, time() );
}

// multiply firstvalue with secondvalue

elseif( $action == &acute;result&acute; ) {
$end_time = microtime();
$dauertmp = explode(&quot; &quot;, $end_time);
$end_time = $dauertmp[0] + $dauertmp[1];
$dauer = $end_time - $start_time;
$exec_time = substr($dauer, 0, 5);
$number = $firstvalue * $secondvalue;
if( $number == $result ) {
$resultstr = &quot;TRUE&quot;;
$trueresult++;
}
else {
$resultstr = &quot;FALSE&quot;;
$falseresult++;
}

if ($type == small) {
get_small_values( $resultstr, $firstvalue, $secondvalue, $exec_time, $trueresult, $falseresult );
} else {
get_large_values( $resultstr, $firstvalue, $secondvalue, $exec_time, $trueresult, $falseresult );
}

}

elseif( $action == &acute;small&acute; )
get_small_values( $resultstr, $firstvalue, $secondvalue, $exec_time, $trueresult, $falseresult );
elseif( $action == &acute;large&acute; )
get_large_values( $resultstr, $firstvalue, $secondvalue, $exec_time, $trueresult, $falseresult );
elseif( $action == &acute;endmath&acute; ) {
$abs_end = date( &acute;i&acute;, time() );
$abs_exec = $abs_end - $abs_start;
$abs_exec = getdate($abs_exec);

if($trueresult == &acute;&acute;) { $trueresult = 0; }
if($falseresult == &acute;&acute;) { $falseresult = 0; }

echo( &quot;<b>Statistics</b>
time of training: $abs_exec[minutes] min. and $abs_exec[seconds] sec.
<br><br>right answers: $trueresult
<br>wrong answers: $falseresult<br><br>
<a href=\&quot;./math.php\&quot;>replay</a>
&quot; );
}



function get_small_values( $resultstr, $firstvaluelast, $secondvaluelast, $exec_time, $trueresult, $falseresult ) {
if( !empty( $resultstr ) ) {
echo( &quot;last execution time : $exec_time sec.
last operation : $firstvaluelast x $secondvaluelast
last operation : <b>$resultstr</b>

&quot; );
}
$start_time = microtime();
$dauertmp = explode(&quot; &quot;, $start_time);
$start_time = $dauertmp[0] + $dauertmp[1];

$action = &quot;small&quot;;
$firstvalue = random( $action );
$secondvalue = random( $action );
echo( &quot;<b>Kleines 1x1</b>

<b>$firstvalue x $secondvalue = </b>
<form action=\&quot;./math.php?action=result&type=small&start_time=$start_time&result=$result&firstvalue=$firstvalue&secondvalue=$secondvalue\&quot; method=\&quot;post\&quot;>
<input type=\&quot;text\&quot; name=\&quot;result\&quot; size=\&quot;4\&quot; maxlength=\&quot;4\&quot;>
<input type=\&quot;hidden\&quot; name=\&quot;trueresult\&quot; value=\&quot;$trueresult\&quot; size=\&quot;4\&quot; maxlength=\&quot;4\&quot;>
<input type=\&quot;hidden\&quot; name=\&quot;falseresult\&quot; value=\&quot;$falseresult\&quot; size=\&quot;4\&quot; maxlength=\&quot;4\&quot;>
<input type=\&quot;submit\&quot; name=\&quot;submit\&quot; value=\&quot;submit\&quot;>
</form>
<a href=\&quot;./math.php?action=endmath&trueresult=$trueresult&falseresult=$falseresult\&quot;>End</a>
&quot;);

}



function get_large_values( $resultstr, $firstvaluelast, $secondvaluelast, $exec_time, $trueresult, $falseresult ) {
if( !empty( $resultstr ) ) {
echo( &quot;last execution time : $exec_time sec.
last operation : $firstvaluelast x $secondvaluelast
last operation : <b>$resultstr</b>
&quot; );
}
$start_time = microtime();
$dauertmp = explode(&quot; &quot;, $start_time);
$start_time = $dauertmp[0] + $dauertmp[1];


$action = &quot;large&quot;;
$firstvalue = random( $action );
$secondvalue = random( $action );
echo( &quot;<b>Großes 1x1</b>


<b>$firstvalue x $secondvalue = </b>
<form action=\&quot;./math.php?action=result&type=large&start_time=$start_time&result=$result&firstvalue=$firstvalue&secondvalue=$secondvalue\&quot; method=\&quot;post\&quot;>
<input type=\&quot;text\&quot; name=\&quot;result\&quot; size=\&quot;4\&quot; maxlength=\&quot;4\&quot;>
<input type=\&quot;submit\&quot; name=\&quot;submit\&quot; value=\&quot;submit\&quot;>
<input type=\&quot;hidden\&quot; name=\&quot;trueresult\&quot; value=\&quot;$trueresult\&quot; size=\&quot;4\&quot; maxlength=\&quot;4\&quot;>
<input type=\&quot;hidden\&quot; name=\&quot;falseresult\&quot; value=\&quot;$falseresult\&quot; size=\&quot;4\&quot; maxlength=\&quot;4\&quot;>
</form>

<a href=\&quot;./math.php?action=endmath&trueresult=$trueresult&falseresult=$falseresult\&quot;>End</a>

&quot;);
}

// get random integer

function random( $action ) {

if( $action == &quot;small&quot; ) {
mt_srand((double)microtime()*1000000);
return mt_rand( 1, 9 );
}

elseif( $action == &quot;large&quot; ) {
mt_srand((double)microtime()*1000000);
return mt_rand( 1, 19 );
}
}

?>


greez
cYrus

KarateKid
28.01.2002, 15:43
@silencer: Meiner Meinung nach lässt PHP nur eine gerine Objektorientierung zu, was sie dann auch wieder nicht nötig macht! :)