Mid-Term Exam (1)
Introduction to Computer Science
NCNU CSIE

Date: October 28th, 2009
Time: 14:10-16:00
Open book; turn off computer & mobile phone

  1. (10%) What are the four major subsystems of a computer defined in the von Neumann model?
  2. (10%) The EBCDIC codes of characters '0', '5', '9' are 240, 245, 249, respectively.
  3. (10%) Consider the following program. 
    1. What will be its output?
    2. If we delete line 90 and replace line 70 with "IF A(I)=0 OR I>50 THEN 130", what will be the output of this program?
      10 REM: ===== Prime Number =====
      20 DIM A(100)
      30 FOR I = 2 to 100
      40 A(I)=1
      50 NEXT I
      60 FOR I = 2 TO 100
      70 IF A(I)=0 THEN 130
      80 PRINT I;
      90 IF I>50 THEN 130
      100 FOR J=2 TO INT(100/I)
      110 A(I*J) = 0
      120 NEXT J
      130 NEXT I
      140 PRINT
  4. (10%) Suppose we allocate 8 bits to store an integer. Write down the binary representation of 0 and -1 in one's complement.
  5. (10%) Suppose we allocate 8 bits to store an integer. Write down the binary representation of -256 and -1 in two's complement.
  6. (10%) If you input two numbers -84 and 16, what will be the output of the following program?

    10 REM: ===== gcd.bas =====
    20 REM: Greatest Common Divisor
    30 INPUT A, B
    40 A=ABS(A) : B=ABS(B)
    50 DO WHILE B>0
    60   A = A MOD B
    70   TEMP=A : A=B : B=TEMP
    80 LOOP
    90 PRINT A
    100 END

  7. (10%) What will be the output of the following program?

    10 REM Sorting
    30 DATA 1, 3, 5, 7, 2, 4, 6
    40 K=7
    50 DIM A(K)
    60 FOR I=1 TO K
    70    READ A(I)
    80 NEXT I
    85 GOSUB 200
    90 FOR I=1 TO K-1
    100    FOR J=I+1 TO K
    110       IF A(I) > A(J) THEN TEMP=A(I): A(I)=A(J): A(J)=TEMP
    120    NEXT J
    125    GOSUB 200
    130 NEXT I
    150 END
    200 REM --- Print out the array ---
    210 FOR H=1 TO K
    220    PRINT A(H);
    230 NEXT H
    240 PRINT
    250 RETURN

  8. (10%) One of your TA was born on November 10th, 1985.  What day is that day? Be sure to show your calculation in addition to your choice.
    1. Sunday
    2. Monday
    3. Tuesday
    4. Wednesday
    5. Thursday
    6. Friday
    7. Saturday
  9. (20%) Convert 81.5625 to IEEE standard floating-point and represent it in binary and hexidemical notations.
  10. (10%) Consider the following BASIC program:
    10 INPUT "N = "; N
    20 DO WHILE N<>0
    30 FOR I=N TO 1 STEP -1
    40 GOSUB 130
    50 NEXT I
    60 FOR I= (1) TO N
    70 GOSUB 130
    80 NEXT I
    90 INPUT "N = "; N
    100 LOOP
    110 END
    130 REM: --- subprogram ---
    140 W = (2)
    150 FOR J=1 TO I
    160 PRINT "*";
    170 NEXT J
    180 PRINT SPC(W);
    190 FOR J=1 TO I
    200 PRINT "*";
    210 NEXT J
    220 PRINT
    230 RETURN

    If we want to obatin the following results, what expressions should be filled into the two blanks, respectively?
    N = ? 5
    ***** *****
    **** ****
    *** ***
    ** **
    * *
    ** **
    *** ***
    **** ****
    ***** *****
    N = ? 6
    ****** ******
    ***** *****
    **** ****
    *** ***
    ** **
    * *
    ** **
    *** ***
    **** ****
    ***** *****
    ****** ******
    N = ? 0
    bwBASIC: