CS 2401 Test #1

Date: Thursday, September 27, 2010.

Name: ___________________________________________________________________

1-2. A list of temperatures recorded at different locations in El Paso can be represented either as an array or as a vector. These temperatures are recorded in the usual US units: degrees Fahrenheit. To supplement their own measurements, our Cd. Juarez colleagues would like to use these temperatures, but they would like to have them in Centigrade (Celsius). The conversion formulas is easy:
tC = (5/9) * (tF - 32).







































3-5. When trying to program Fibonacci numbers, a student made two mistakes: used subtraction 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 on each test.



















































7-8. A student decided to earn some money by designing a UTEP-related pattern for T-shirts. Write a method that uses recursion to print the following pattern
UTEP
UTEP UTEP
UTEP UTEP UTEP
up to a row with UTEP repeated n times.















































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