next up previous
Next: About this document ...

CISP365 Practice Midterm 1

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 90%, ``B'' means at least 70%, ``C'' means at least 50%, ``D'' means at least 30% and ``F'' means below 30%. The break points for the final grade are now 24.16%, 45.83%, 67.50% and 89.16% as minimums for ``D'', ``C'', ``B'' nad ``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 XX, there are YY questions.

  1. Which of the following fragment of code does/do not guarantee to produce any output (from the execution of the writeln statement)? Assume variable X is defined, but its value is not provided.
    1. if X < 0 then
        writeln('something')
      
    2. while X >= 102 do
        begin
          writeln('in a loop!');
          X := X - 1
        end
      
    3. repeat
        writeln('huh?');
        X := X div 2
      until X < 2
      
    4. 1a and 1b
    5. 1a, 1b and 1c
  2. What is X mod Y? Assume X and Y are both positive.
    1. X div Y
    2. Y div X
    3. (X div Y) * Y
    4. X - ((X div Y) * Y)
    5. Y - ((X div Y) * X)
  3. The value represented by 500 (base 10) has a least significant digit of zero in the representation of which of the following bases?
    1. 2
    2. 4
    3. 6
    4. 8
    5. all except 6 and 8
  4. Assume W and Y are non-negative and X is positive. What is the value of Z printed by the writeln statement in the following fragment of code? Express the value of Z as an express of the original values of W, X and Y before the loop.
    Z := Y;
    while W > 0 do
      begin
        W := W - 1;
        Z := Z + X
      end;
    writeln(Z)
    
    1. W * X + Y
    2. W + X * Y
    3. W * Y + X
    4. X * Y * W
    5. Y
  5. What does the following code do (what is Y at the writeln statement)? Assume X is a positive integer, and Y is an integer variable.
    Y := 1;
    while Y < X do
      Y := Y + Y;
    writeln(Y)
    
    1. Y must equal X
    2. Y is a power of 2 that is greater than or equal to X
    3. X is a power of 2 that is greater than or equal to Y
    4. Y is always X+1
    5. Y is always X-1
  6. What is the output of the following program?
    var
      x, y : integer;
    procedure p1;
      begin
        x := x + y
      end;
    procedure p2;
      begin
        y := x * 2
      end;
    begin
      x := 20;
      y := 2;
      p2;
      p1;
      p1;
      writeln(x,',',y)
    end.
    
    1. 60,24
    2. 50,22
    3. 100,40
    4. 100,44
    5. 70,24
  7. What is the behavior of the following fragment of code? Assume X is an integer variable.
    X := 1;
    while X < 20 do
      writeln(X);
    X := X + 1
    
    1. it prints 1 infinitely
    2. it prints all the integers from 1 to 20
    3. it prints 20
    4. it prints 21
    5. it enters an infinite loop that does not print anything
  8. Given that variables X, Y and Z have values 22, 3 and 12 respectively, what does the following fragment of code print?
    if (X < Y) and (X < Z) then
      writeln('case 1');
    if (Y < X) and (Y < Z) then
      writeln('case 2');
    if (Z < X) and (Z < Y) then
      writeln('case 3')
    
    1. the code prints nothing
    2. case 1
    3. case 2
    4. case 3
    5. case 1
      case 3
      
  9. What is the value of variable X when it is printed?
    X := 0;
    Y := 0;
    while X < 5 do
      begin
        X := X + Y;
        Y := Y + 1
      end;
    writeln(X)
    
    1. 4
    2. 5
    3. 6
    4. 7
    5. 8
  10. Which of the following base-5 numbers is a multiple of $10_{10}$?
    1. $1410_5$
    2. $10_5$
    3. $100_5$
    4. $120_5$
    5. $1000_5$
  11. What does the following program print?
    var 
      j : integer;
    begin
      j := 0;
      while j < 4 do
        begin
          write((2 + j * 3) mod 4, ' ');
          j := j + 1
        end;
    end.
    
    1. the program completes without printing anything
    2. 2 1 0 3
    3. 2 5 8 11
    4. the program is syntactically incorrect
    5. the program prints numbers in an infinite loop
  12. Which of the following is not identical to this code fragment (as far as the execution of block1 and block2 is concerned)? Assume neither block1 nor block2 modifies X.
    if X < 0 then
      block1
    else
      block2
    
    1. if X >= 0 then
        block2
      else
        block1
      
    2. if X < 0 then
        block1;
      if X >= 0 then
        block2
      
    3. if X >= 0 then
        block2;
      if X >= 0 then
        block1
      
    4. if X < 0 then
        block1
      else 
        if X >= 0 then
          block2
      
    5. all the other choices behave the same as the code fragment in the question



next up previous
Next: About this document ...
Tak Auyeung 2003-09-22