PHP Exercise 16
Input file:
# of points in running average:

"; fprintf($out,"%d, %d, %d, %d, %f, %f\n",$m,$d,$y,$dayCount,$hi,$lo); } else { echo ($i+1)." ".$hi." ".$lo." ".$sum/$n."
"; fprintf($out,"%d, %d, %d, %d, %f, %f, %f,\n",$m,$d,$y,$dayCount,$hi,$lo,$sum/$n); } } $k=$n; while (!feof($in)) { $oldest=array_shift($a); // remove oldest element fscanf($in,"%d %d %d %f %f",$m,$d,$y,$hi,$lo); $a[$n-1]=($hi+$lo)/2.; // add new element $sum=$sum-$oldest+$a[$n-1]; echo ($k+1)." ".$hi." ".$lo." ".$sum/$n."
"; $dayCount++; fprintf($out,"%d, %d, %d, %d, %f, %f, %f,\n",$m,$d,$y,$dayCount,$hi,$lo,$sum/$n); $k++; } fclose($in); fclose($out); ?> PHP Exercise 8. Note that some of you did not prevent the maximum cumulative dose from being exceeded. You added a final dose that exceeded the maximum cumulative dose and THEN stopped the loop. Too late! (Recall the "500 pound gorilla" problem discussed earlier.) "; echo "minimum individual dose = " . $min_individual . "
"; echo "maximum individual dose = " . $max_individual . "
"; $i=0; $delivered=0; $maxed_out=false; do { $i++; $dose=rand($min_individual,$max_individual); if (($delivered+$dose)<=$max_cumulative) { $delivered+=$dose; echo $i . "\t" . $dose . "\t" . $delivered . "
"; } else { echo $i . "\t" . $dose . "\tnot delivered
"; $maxed_out=true; } } while (!$maxed_out); echo "total delivered = " . $delivered . "
"; ?> Search for a person... First Last ID Phone Sam Malone 00335 5551234986 Diane Chambers 10398 9992349876 Norm Peterson 20987 8889994444
Search for:
This is a:
First Name:
Last Name:
ID:
Phone Number (xxxyyyzzzz):
or List All:
"; } fclose($in); ?>