Sample Midterm #1 A22.0002
The exam will be on Wed, March 6 Samuel Marateck
The grader is at the Education site T &TH 1:30-2:30

1. (30 points.) Write a program that reads a goup of contiguous numbers from the keyboard. For instance 45231 such that the first digit indicates how many digits follow. Thus the "4" indicates that four digits will follow. The program should sum the remaining digits. Thus if the inputted digits are 523167, the result would be the sum of 2, 3, 1, 6, and 7. The program should be written in general.

Hint. Use J, as the loop control variable, where VAR J:integer

If First is the variable that the first digit is read into, is it read before or after the FOR-DO loop?

What does the FOR statement look like in terms of First?

2. (10 points.) What does the following produce?

```PROGRAM Test1
VAR J:integer;
BEGIN
FOR J:=1 TO 5 DO
writeln(J:J, J:J)
END.
```

Hint when J is 1, what is the value of J:J, J:J, what does the :J part indicate?

3. (15 points) In the following, state the type and value of each of the following expressions. If the expression contains an error, write invalid as the type and omit the value.

```     EXPRESSION                    TYPE           VALUE

200.0 div 4.0                     __________     __________

3 mod 4 * 3 div 2 - 5 mod 2       __________     __________

(5 + 4) mod (1 + 2) + 5 / 5       __________     __________
```

4. In the parts (a) and (b), assume that all the variables are INTEGER. Given the following input:

```
13 24
4 6 8
6 3 5
7
```

(a) (5 points) What will be assigned to A, B, C, D, and E in:

```
```

(b) (5 points) What will be assigned to A, B, C, D, and E in

```
```

(c) (5 points) What will be assigned to A, B, C, D and E in

```       readln (A, B, C, D, E)
```

if all these variables are declared as Char?

5. (5 points) Given:

```		var silly : integer ;
```

Which of the following causes the number stored in silly to be printed. (circle one)

```a) writeln ( silly	) ;
b) readln  ( silly	) ;
c) writeln ( 'silly ' ) ;
d) readln  ( 'silly'  ) ;
```

6. (5 points) Given:

```var answer1, answer2 : ___________ ;
begin
writeln( 'Enter both answers, one per line' ) ;
end.
```

Fill in the blanks so that no errors occur if the user types:

```     3
4.0
```

7. (20 points) How many times would the FOR-DO loops beginning with the following statements be executed?

```          _____   a. FOR J:= 4 DOWNTO 5 DO
_____   b. FOR J:= 3 DOWNTO -1 DO
_____   c. FOR CH:= 'D' TO 'A' DO
_____   d. FOR J:= -4 TO 3 DO
_____   e. FOR CH:= '3' TO '5' DO
```