Midterm #1 V22.0101

October 28, 1996 Samuel Marateck

1. (30 points.) A number consists of 0s and 1s, for instance, 10011,
Write a procedure which reads such a number using an `eoln` such that
the digits are read as characters. The procedure should count the
amount of 1s in the number. If the number of 1s is odd, the procedure
should append a 1 to the beginning of the binary number, else it
should not change the number. Thus our original number becomes 110011;
it should be passed back as an integer to the main program. If the
original number were 100001, then 100001 would be passed back.

2. (20 points) Write a program that produces the following pattern using
nested loops.

x xx xxx xxxx xxxxx xxxxxx xxxxxxx xxxxxxxx xxxxxxxxx

Hint: Print 8 blanks and one x, then 7 blanks and and one x, etc.

3. Write a procedure called `smallest_on_line`

that finds the
smallest integer in a line of data and returns that integer as a var
parameter. The heading should be ```
smallest_on_line( var small :
char );
```

. Thus if the line is 12 34 56 78 2 9, the procedure returns 2.
Use the `eoln` function.

4. Write a program fragment that uses `smallest_on_line`

to find
the smallest number in a group of lines that ends with `^Z`

( an end of file).

5. Evaluate the following and also specify the type of the result.
If the expression contains an error, write *invalid*.

(a) 20 mod 5 (b) 3 + 4 * 3 mod 2 mod 2 - 5 mod 2 (c) 6 * 5 / 4 + 7 div 6.0 (d) 8 mod 5 div 2 + 4.0

Fri Sep 5 00:02:58 EDT 1997