CS 117
Midterm 1
Ondich
Friday, February 9, 1996

This is a closed-book 68-point exam. Write your answers in the bluebook. If you want to put an answer on the exam itself, say so in the bluebook and put your name on the exam. Explain your answers clearly.

  1. (10 points) What output does the following program produce? You may assume that it compiles and runs (it does--I tried it).

    
    program something(output);
    
    var		a, b : integer;
    
    procedure anything( a : integer );
    begin
    	a := 5
    end;
    
    procedure nothing( var c : integer; d : integer );
    begin
    	c := 6;
    	d := 7
    end;
    
    procedure everything( var e, f : integer );
    var		temp : integer;
    begin
    	temp := e;
    	e := e + f;
    	f := temp
    end;
    
    begin
    	a := 1;
    	b := 2;
    	anything( b );
    	writeln( 'First: ', a, b );
    
    	a := 1;
    	b := 2;
    	nothing( a, b );
    	writeln( 'Second: ', a, b );
    
    	a := 1;
    	b := 2;
    	everything( a, b );
    	everything( b, a );
    	writeln( 'Third: ', a, b )
    end.
    
    

  2. (10 points) Write a function that takes a character as input from the calling routine and returns true if the character is a digit ('0', '1',...,'9'), and false otherwise. Note that this function should contain no read, write, readln, or writeln calls.
  3. (10 points) Write -25 and 18 in eight-bit two's complement notation. What base ten number does the eight-bit two's complement number 10010011 represent?
  4. (10 points) A few questions about function/procedure parameters.
  5. (8 points) Each of the following code fragments prints out an inexplicable message some number of times. How many times does each message get printed?

    	for i := 1 to 10 do
    		for j := 2 to 7 do
    			writeln( 'Shrews choose blue shoes' );
    

    	for i := 1 to 10 do
    		for j := i to 10 do
    			writeln( 'Ticks pick six sticks' );
    
  6. (6 points) Program errors can be classified as "compile-time" errors or "run-time" errors, depending on when the errors are first evident. Give an example of a program error that the compiler will catch (that is, a compile-time error). Give an example of a program error that the compiler will not catch, but that will appear when you run the compiled program.
  7. (2 points) I'm going to Philadelphia for a conference next week. What should I read on the plane?
  8. (12 points) The song "99 bottles of beer on the wall," designed especially for the torture of parents, has 99 verses, starting with

    	99 bottles of beer on the wall
    	99 bottles of beer
    	Take one down and pass it around
    	98 bottles of beer on the wall
    

    and ending with

    	1 bottle of beer on the wall
    	1 bottle of beer
    	Take one down and pass it around
    	0 bottles of beer on the wall
    

    Write a procedure that will print out the lyrics to the song "N bottles of beer on the wall," where N is the procedure's input parameter. (The procedure will start with "procedure Beer( N : integer );".)





Jeff Ondich, Department of Mathematics and Computer Science, Carleton College, Northfield, MN 55057
(507) 663-4364, jondich@carleton.edu