CS 2401 Test #1

Date: Wednesday, September 26, 2010.

Name: ___________________________________________________________________

1-2. A list of students in a class can be represented either as an array or as a vector. Let us assume that one of the students decided to drop the class; in this case, we need to delete this student's name from our list.









































3-5. When trying to program Fibonacci numbers, a student made two mistakes: used multiplication instead of addition, and used a wrong initial value n(1) = 2 instead of n(1) = 1. As a result, he got a sequence of numbers n(0), n(1), ..., for which n(0) = 1, n(1) = 2, and n(i) = n(i-1) * n(i-2) for all other i > 0. Since the numbers are unusual, it is not easy for a TA to check the correctness of the student's code. By comparing these two methods, what can you say about the advantages and disadvantages of recursive versus non-recursive techniques?
















































6. In a 2-D array, let g[s][t] represent the grade of student s on test t. Based on this input, we need to find the average grade of every student.




















































7-8. A student is so happy with his straight A grades that she decides to print them in a nice way. Write a method that uses recursion to print the following pattern
A

A A

A A A
up to a row with n A's.













































9. What are advantages and disadvantages of using enumerated types as opposed to a list of strings? Give examples.