The two character sections should be allocated one more space than the number of characters to allow for the null terminating character.
Also, the class must have a public attribute or else the sections cannot be accessed.
Prob 2:
This was very similar to Practice Problems, Set 2, number 5. In the problem, the number of scores was 20, whereas on the exam, it was 25.
Prob 3:
The only difference between a class and a struct is whether the components are public or private by default. See Notes N14, first section. Both can have member functions in C++ (but a struct in C cannot have member functions). See Notes N15, first section.
Prob 4:
People had some difficulties doing the pushing and popping correctly. This was similar to Practice Problems, Set 3, Number 8.
Prob 5:
Some people had some difficulty with the arithmetic and the fact that a[0] was 1 not 0. A few people did not have all 5 numbers as output or reversed the order (which should be high to low).
Prob 6:
Inside the function, one has to use the full variable name, i.e., person.units since this is not a member function and the class variable person is a parameter.
A number of people did not interpret "initial charge of $8000 plus $400 for each unit over 20" correctly.
One has to be careful with independent if statements (i.e., not using an else clause). Independent if statements mean that each condition must be evaluated (with else clauses, the unnecessary tests are omitted). Independent if statements also mean that one needs to be careful with the condition so that a given value does not result in two different assignments being done.
Prob 7:
Bubblesort (not selection sort) works by swapping adjacent elements.
Prob 8:
There seemed to be some confusion between the subscript and the value contain in the array element.
Also, when the return statement is executed, either in the main program or in a function, the code ends and returns to the calling program (or the program merely stops). The return does not force the loop to end early and the program to continue after the loop with the other cout statement.
Prob 8:
Several people overlooked the -1 that was part of the recursive definition. Others changed the plus sign to a negative.
Prob 9:
Besides (1) overlooking the "-1", (2) replacing the + with a -, (3) (sometimes) replacing f(i) with i, some people had arithmetic problems and problems with tracing the recursion from f(5) to the base cases. In such problems, the best way to get the correct answer is to start with the base case and "work up."
x
x
x x x
x x x
x x x
x x x
x x x x
x x x x
x x x x
x x x x x
20 30 40 50 60 70 80 90
(1 0 0 0 4 8 10 8)
This page is maintained by Dennis C. Smolarski, S.J.
dsmolarski@math.scu.edu
© Copyright 2000 Dennis C. Smolarski, SJ, All rights reserved.
Last changed: 7 November 2000.