Overall, students did well on the exam. If you haven't done well on a particular question, be sure to re-do it, perhaps with the help of a member of the course staff, instead of just reading the solution.
(b) boolean operation on chars
Some students did not know that one can perform relational operations,
<= and >= in this case, on chars and char
variables. A version of this question was actually in Lab Exercise 10!
while-loop version simply by pattern matching but did not
understand (could not explain) what the given code did. Some students did
not understand what the given code did and wrote incorrect code. (But a
third of the class did answer this question perfectly.)
The given code returns true (1) if the input vector contains at least one positive value; otherwise returns false (0). The most common errors were
&& does when the operands are integers
(1 or 0). E.g., the expression 1 && 1 gives 1, just as
1 && (pi>3) gives 1
~ does. For
example,
A = pi>3; % A is true (1)
A = ~A; % NEGATION. A becomes false (0)
-Inf
uint8)uint8. Remember this: a uint8 value is
capped at 255 (and the lower bound is 0). If you add two uint8
values together you may get an overflow, e.g.,
x=uint8(200)+uint8(100) results in x getting the
value 255, not 300. Some students neglected to handle the third dimension,
the multiple layers of the 3-d array. A common algorithmic error appeared
in the calculation of the indices
in the reduced size array: an extra loop is NOT necessary for
calculating the reduced array indices from the original array indices.
Grading error: During grading, a point was deducted for
assuming that the parameter P always has three layers. That
point deduction was incorrect--please submit a regrade request if you lost
a point due to assuming that the array has three layers. (The
reason this happened was that a generic 3-d array does not necessarily have
only three layers--in the third dimension there can be any number of layers
and not just three. However, in the 3-d image arrays that we've
dealt with, we have always seen 3-d arrays with exactly 3 layers.)
chars and nested loops)
for i=1:nr
for j=1:nc % this loop is extraneous!
spaceIndex = 1
while M(i,spaceIndex) ~= ' '
spaceIndex = spaceIndex + 1;
end
end
end
You need one loop to move row to row (the outer for-loop above) and
another to move through the columns as you perform the search column
by column; so you already have the two loops for traversing the 2-d
array. A third loop was not necessary.
Other errors include simplifying the problem by assuming that the netID has a fixed length, there's a fixed number of digits before or after the decimal place of the gpa, ..., etc.
% Action to take after prelim
if yourScore > 88
toDo= celebrate + later look at the solution
elseif yourScore > 70
toDo= redo problems + later check solution
else
toDo= meet with a course staff member to go over exam ...
+ stay caught up from now on
end