next up previous
Next: About this document ...

CISP365 Practice Midterm 2

Prof. Tak Auyeung

Instructions: You may bring any material that is handwritten or printed prior to the examination to help you. You can also bring a calculator if you think it may help you. However, you can only use the calculator for numerical computations only. You cannot let your calculator compile a program, or to communicate with others.

You, as an individual, are expected to do your own work. This means you cannot seek, receive or otherwise acquire any assistance except clarifications from the professor during an examination. Any communication involving the contents of the subject matter or the examination is considered cheating. Do not initiate or accept such communication, or the result of your examination is automatically voided.

New rules, read this! As of 2003.09.22, I no longer deduct points for wrong answers. Each correct answer is worth one point, each wrong answer is worth zero point, and each unanswered question is also worth zero point. This means you should guess and leave no question unanswered.

As a result, I also need to adjust the letter grade assignment break points. For your individual examinuation, ``A'' means at least 94%, ``B'' means at least 74%, ``C'' means at least 54%, ``D'' means at least 34% and ``F'' means below 34%. The break points for the final grade are now 26.83%, 48.5%, 70.17% and 91.83% as minimums for ``D'', ``C'', ``B'' and ``A'', respectively.

Please note that this change does not affect your letter grade at all, it is just a number game to make some people feel better about guessing.

Make sure you write down you name on the upper right corner first, otherwise I cannot give points to anonymous students!

The baseline is 10, there are 12 questions.

  1. Which reserved word should fill in ____ in the following code so there is no syntax error?
    var
      knives : 
        ____
          i : integer;
          x : real
        end;
    
    1. array
    2. record
    3. integer
    4. boolean
    5. real
  2. What does the following program print?
    procedure p1(var x : integer; var y : integer);
      begin
        y := x + y div 2;
        x := y + 2 * x
      end;
    
    procedure p2(var x : integer; var y : integer);
      begin
        y := x + y div 2;
        x := y + 2 * x;
        p1(x,y)
      end;
    
    var
      x, y : integer;
    begin
      x := 10;
      y := 20;
      p2(x,y);
      writeln(x,' ',y)
    end.
    
    1. 150 30
    2. 150 50
    3. 40 10
    4. 40 20
    5. 40 30
  3. What does the following program print?
    var
      a : array [0..2] of integer;
      i : integer;
    begin
      i := 0;
      while (i < 3) do
        begin
          a[i] := (1 + i * 2) mod 3;
          i := i + 1
        end;
      i := 0;
      while (i < 3) do
        begin
          write(a[a[i]],' ');
          i := i + 1
        end;
      writeln
    end.
    
    1. 0 1 2
    2. 2 1 0
    3. 0 2 1
    4. 2 0 1
    5. 1 2 0
  4. What does the following Pascal function does? Assume parameter a is a sorted array of n integers that are non-decreasing.
    function f(var a : array of integer; n : integer) : integer;
      var i : integer;
          x : integer;
      begin
        i := 0;
        x := 0;
        while i < n do
          begin
            x := x + a[i];
            i := i + 1
          end;
        f := x
      end;
    
    1. finds the smallest value in a
    2. finds the largest value in a
    3. finds the average value of a
    4. finds the sum of values in a
    5. none of the other choices
  5. What is an abstract data type?
    1. It is a Pascal construct.
    2. It is defined by the type reserved word.
    3. It is a data type accessed following certain disciplines used in programming.
    4. 5a and 5c
    5. none of the above describes an abstract data type.
  6. Assume as array a has the following elements: 32 1 -4 23 11 23 (from index 0 to index 5, respectively). What is the value of the element at index 0 after the following code completes? Assume i and x are Integer variables.
    i := 0;
    while i < 3 do
      begin
        if a[i] < a[5-i] then
          begin
            x := a[i];
            a[i] := a[5-i];
            a[5-i] := x
          end;
        i := i + 1
      end;
    
    1. cannot be determined
    2. 32
    3. -4
    4. 23
    5. determined, but it is none of the choices provided
  7. The floating point number $1.1001_2 \times 2^{100_2}$ represents which value?
    1. $1.1001_{10}$
    2. $1.5625_{10}$
    3. $6.25_{10}$
    4. $3.125_{10}$
    5. $110.01_{10}$
  8. What is the output value of the following program?
    type
      c = 
        record
          r : real;
          i : real
        end;
    procedure ca(var s : c; x : c);
      var
        t : c;
      begin
        t.r := s.r + x.r;
        t.i := s.i + x.i;
        s := t
      end;
    var
      x, y : c;
    begin
      x.r := -2.0;
      x.i := 2.0;
      y.r := 7.0;
      y.i := -5.0;
      ca(y, x);
      writeln(y.r,',',y.i)
    end.
    

    1. 5,-3
    2. -2,2
    3. 7,-5
    4. the output is undetermined
    5. this program has at least one syntax error
  9. What is true about the following binary search code? Assume a is the array that has size non-decreasing integers. mystery is the value we are searching for. lo, hi and me are variables of Integer type.

    We know that size is some integer larger than two.

    lo := 0;
    hi := size-1;
    repeat
      me := (hi + lo) div 2;
      if mystery > a[me] then
        lo := me + 1
      else if mystery <= a[me] then
        hi := me
    until (lo > hi) or (mystery = a[me]);
    
    1. this code may get stuck in an infinite loop
    2. this code has a syntax error
    3. this code is always stuck in an infinite loop
    4. this code works correctly
    5. this code always terminates, but it may not find the item
  10. When does function f returns TRUE? This function expects array a to have n elements, with the index of the first element being 0.
    function f(var a : array of integer; n : integer) : boolean;
      var
        i : integer;
        b : boolean;
      begin
        i := 0;
        b := true;
        repeat
          b := (a[i] < a[i+1]);
          i := i + 1
        until (not b) or (i >= n-1);
        f := b
      end;
    
    1. when elements in a are in non-decreasing order
    2. when elements in a are in increasing order
    3. when elements in a are not in non-decreasing order
    4. when elements in a are not in increasing order
    5. none of the other options is true



next up previous
Next: About this document ...
Tak Auyeung 2003-11-03