I’ve finally gotten around to finishing my grading for my CPS 306 course, which is the web programming course I’m teaching for the University of The Gambia. The midterm exam went, how does one say, rather poorly. The class average was a mighty 38. Which, sadly, is actually just below a D on the Gambian grading scale. Now for the better news… The class average for my final exam was a 51, which is slightly above a C for the kids keeping score at home, which I’m actually pretty ok with. Almost everyone went up from the midterm and one student increased his score a powerful 43 points. The lowest drop on the other hand was 10 points. There are a number of factors that might contribute to this, for one I think the test was probably a little easier. I didn’t intend to do this but I think it ended up happening. Another issue my have been that the midterm was the first test or quiz they’ve seen from me so they might not have been used that particular style. Finally, no matter how much I try to emphasize this my students tend to insist on thinking that the midterm exams are much easier than the finals…
Anyway. I did want to post the answer which caused the most tragedy in my little heart…
The question was: Create a function that takes an array and returns the average of the array. If the function is called with no arguments the function should return -1.
Answer:
function average($i $j){
$i = average Array[];
$i = [] = 4;
$i = [] = 2;
return($i as average_array)
else{
echo(-1)
}
Now, for those of you who don’t know php or programming this is a pretty bad… If nothing else, he just picks two random numbers and doesn’t even try to average those. For reference’s sake here is what it might look like
function avg($numbers = FALSE){
if (!$numbers) return -1;
foreach ($numbers as $value){
$total = $value + $total;
$count++;
}
return $total/$count;
}
Hahaha that made me smile. I’ve seen better PHP out of the Watters brothers…
I knew you’d like it buddy.