These are some notes I came up with while grading the exams.
Even if you were satisfied with your performance on the exam, it may still be helpful to look over these comments, since in some cases I hint at how questions on future exams might be phrased. If you were disappointed in your performance, that's even more reason to look over these notes carefully.
This is not a complete answer key or rubric. For the questions that nearly
every student got correct, I have not supplied answers here. Rather, I have
supplied correct answers and comments on some incorrect answers only in cases
where I think some additional comment might be helpful to the class' learning,
or to CISC105 instructors in making up future exams on this material.
These were fairly straightforward; if you have questions about them, I'll go over them in class or during office hours. One note: I threw out question 1 since there was a typo, and some folks misunderstood my correction to the typo. As a result, you all got "two free points" on the exam.
On this question, many students had perfect or nearly perfect solutions. Among the solutions that received less than stellar grades, there were several common problems:
length, and do a scanf for
length before you can use length on the right hand side of an assignment
statement!
in C source code.
You can't use
as a variable in C! You
need to spell it out as PI (if it is a #define)
or pi (if it is a variable). Likewise, you can't use symbols
such as <=.(10 pts) Write a C function (just a C function, not a complete program)
called maxOfThree that takes three integers as parameters, and
returns the maximum of those three integers.
Optional: If it will help you, you may write a function maxOfTwo first,
and then write maxOfThree in terms of the maxOfTwo function.
However, that is not required, nor will it earn you extra credit. It is just
an option that you have.
Comments on this problem: Many students were able to answer this question with no trouble. However, I was disappointed at the number of students who still do not have a handle on what a "function" is in the C programming language. The question was very clear: it asked for a function, NOT a complete C++ program. A function takes its values from its parameters, and returns a value via the return statement.
Unless the instructions specifically tell you to prompt for a value, read a value or print a value, there should NEVER be a scanf or printf in a problem that asks you to write a function.
Let me repeat that for emphasis: unless the instructions specifically tell you to prompt, read or print, NEVER put a scanf or a printf inside a function! Unless told otherwise, use only the function parameters for input, and the only the return statement for output!
There are many possible correct answers to this problem. Here are just two of them:
|
Here's another answer. Note that the instructions were specific: if you wanted to use maxOfTwo in your answer, you had to define it as well. That means a full function definiton must appear in your answer!
int maxOfTwo(int a, int b)
{
if (a>b)
return a;
else
return b;
}
|
Number conversions:
Few students had any trouble coming up with the correct answer: 1 0110
0101.
A common error was to forget one digit when counting up the digits from
right to left; for example:
256 64 32 16 8 4 2 1
256 128 64 32 16 4 2 1
256 128 32 16 8 4 2 1
Each of the lists above is missing "one bit".
Some students confused "decimal to binary" with "hexadecimal to binary".
If the question asked you to convert from hexadecimal to binary, the
answer would be 0011 0101 0111 (why?)
What if the question asked for octal to binary? Then the answer
would be 011 101 111 So it is very important to know
what conversion is being asked
for.
A challenge for the next exam: how would you convert 73 from decimal
to octal (answer: 111) ? How about decimal to hexadecimal (answer:
49)?
See Chapter 1 for more help on this.
Another possible question for the next exam: convert 2A from hexadecimal
to decimal
The correct answer is 42. "A" is in the one's place, and
represents 10. "2" is in the 16's place, which means that it
contributes "2 x 16 = 32" to the total.
So the total is 32 + 10 = 42.
When I gave this question on another exam, I noticed that some folks
took "2" + "10" and
came up with "12". Don't make that mistake!
Place your answer in the grid provided, one character or space per box. You might not need all the spaces in the grid provided.
If you make a mistake, and want to start over, there are extra grids on the next page; just cross out the grid above, and indicate that your answer is on the next page.
/* q1.c an example program that lacks comments */
#include <stdio.h>
int main (void)
{
int a, b, c, d, e;
a = 5;
b = 7;
c = a * 3 - 4 * b;
d = b / 2;
e = a++;
printf("a=%d\n", a);
printf("b=%d\n", b);
printf("c=%d\n", c);
printf("d=%d\n", d);
printf("e=%d\n", e);
}
Correct Answer
| a | = | 5 | |||||||||||||||||
| b | = | 7 | |||||||||||||||||
| c | = | - | 1 | 3 | |||||||||||||||
| d | = | 3 | |||||||||||||||||
| e | = | 5 |
a="
etc on each linea++ "gives
its value" to the expression before the variable
a is incremented.
/* q2.c Another program with no comments */
#include <stdio.h>
int main (void)
{
int count;
count = 0;
while (count <= 2)
{
printf("*");
count++;
}
printf("\n");
printf("Done\n");
return 0;
}
Correct Answer
| * | * | * | |||||||||||||||||
| D | o | n | e | ||||||||||||||||