From marateck@merv.cs.nyu.edu Sat Dec 7 19:30 EST 1996 Return-Path: Received: from cs.NYU.EDU by spunky.cs.nyu.edu (SMI-8.6/1.20) id TAA23555; Sat, 7 Dec 1996 19:30:16 -0500 Received: from MERV.CS.NYU.EDU by cs.NYU.EDU (4.1/1.34) id AA17272; Sat, 7 Dec 96 19:35:05 EST Received: from localhost by MERV.CS.NYU.EDU (4.1/1.30) id AA17232; Sat, 7 Dec 96 19:30:42 EST Date: Sat, 7 Dec 1996 19:30:42 -0500 (EST) From: Sam Marateck To: michael overton Subject: correct versionof sample_final.html Message-Id: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Content-Length: 6934 Status: RO Michael, I changed the html version so that the incorrect img references that appear as ?s are replaced with the proper insertions. Here it is: Could you replace the sample_final.html on the Home page and your class page with this one? Thanks, --Sam No Title

V22.0101 Intro to CS I Fall 1996

The exam is Monday, December 16, at 2:00-3:50pm, on the 7th floor of the MAIN BUILDING. (Section 2: Room 713; Section 3: Room 714; Section 4: Room 703).

Sample Exam Questions

1. Write a procedure using the while statement which reads integers, one per line, from the input and adds them up, stopping when the number 0 is read. It should then print the sum and the number of integers which were read, not counting the 0.

2. Write another procedure which does the same thing using the repeat statement.

3. Write a Pascal program to print out the Fibonacci numbers 0, 1, 1, 2, 3, 5, 8, 13, 21 (each number being obtained by adding the previous two together). Stop when the numbers exceed 1000.

4. Write an integer-valued function which takes as a parameter an integer n and returns the value 1 + 2 + ..+ n. For example, if n has the value 5 the function should return the value 15, and if n has the value 2 the function should return the value 3. If n = 0 , return the value 0.

5. Write a function named `sum_divisors` which takes an integer parameter `N`, and returns the sum of all integers in the range 1 to `N-1` that divide into `N` exactly (with zero remainder). For example, suppose `N` has the value 6. The numbers 1, 2 and 3 all divide exactly into 6, but 4 and 5 do not. So, since 1 + 2 + 3 = 6, `sum_divisors`(6) should be 6. Now suppose `N` has the value 9. The numbers 1 and 3 divide exactly into 9, but no other number less than 9 does. So, since 1 + 3 = 4, `sum_divisors`(9) should be 4. You can assume that `N` >1.

6. Write a function which does the same thing as the built-in `chr` function, using the information that the Ascii code for a blank is 32. The function should work for any input value from 0 to 255. Hint: if the value is 32, just return the blank character; if the value is greater than 32, use `succ` to find the desired character, and if the value is less than 32, use `pred` instead.

7. Assume the declaration
```    type IntArray = array[1..max] of integer;
{assume max has been declared in a const statement}
```
Write a procedure which takes one parameter: a variable parameter X of type `IntArray`. Assume that all of the elements (1 through `max`) of the array have been assigned values. The procedure should reverse the order of the elements of the array X. Thus the first element should be interchanged with the last, the second with the second-to-last, etc. Be sure the program works in both the case that `max` is even and the case when it is odd. For example, if the array has elements 5, 3, 17, 21, 2 on entry, then on exit it should have elements 2, 21, 17, 3, 5.

8. Assume the declaration
```type BingoBoard = array [1..N, 1..N] of Boolean;
{assume N has been declared in a const statement}
```

Write a procedure named `ReadBoard` with one parameter `B` of type `BingoBoard`, which reads a pattern from an input file (consisting of X's and blanks, just as for the game of life data files) and sets each array element to either true or false depending on whether the corresponding file entry was an X or a blank. Just as in the game of life, do not assume that the file is padded with blanks. You must use `while not eoln` and `while not eof`.

9. Write a Boolean function named `RowBingo` with one parameter `B` of type `BingoBoard`, and which returns the value `true` if `B` has a row with all `N` elements in the row set to the value `true`. Otherwise, the function returns the value false. Remember that the first index of the array is the row index. For example, if `N` = 5 and the board has the configuration
```       F F T T T
T F T T T
F F T F F
F T T F F
T F T F F
```
the function should return the value `false`.

10. Using the same declarations as you used in the final database homework, write a procedure which searches for a given name in the database, and doubles the hourly pay for this person. Note: there will certainly be a question using arrays of records on the exam. Other possible sample questions would be similar procedures to the ones you wrote for the final homework.

11. Consider the declarations
```   type airport = (jfk, lga, ewr, dfw, sfo, lax);
AirArray = array[airport, airport] of integer;
```
Write a procedure which takes as input a variable `miles` of type `AirArray`, which stores the mileage between airports. For example, `miles[lga,jfk]` is the distance in miles between La Guardia and JFK. The procedure should return two parameters giving the pair of airports which are furthest apart.