V22.0101 Intro to CS I Fall 1998
The exam is Weds. Dec 23, from 2:00 to 3:50pm. Section 2 (Boppana) will be in the MAIN BUILDING on the second floor, room 207. The Marateck sections will be on the 4th floor of the MAIN BUILDING. (Section 3: Rooms 406 and 408; Section 4: Room 407).
Sample Exam Questions
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.
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.
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
.
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 Fthe function should return the value
false
.
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.