308-208 - Computers in Engineering - Previous Midterms

Midterm Fall 1994


1. (10 minutes, 10 points)

Classify each of the following by placing each one under the appropriate column in the table. Assume no explicit declarations.
.GT.     0       .T.          NAME*7     -10.7
+308       TEST0   _LESS_F123S  I  
.FALSE.  10,512  *NEW         13.0001    NOT 
$20.00   ZERO    73202        .EQUAL.    RESULTS

2. (10 minutes, 12 points)

What will the following program print?


         INTEGER a, b, c
         a = 13.0/4
         b = 1.5**2     
         c = 3/(1.0 - 7) * 3
         d = 7/3*2
         e = 2*3**2     
         f = b - 1.5
         PRINT *,a,b,c,d,e,f
         END


3. (10 minutes, 15 points)

What will the following program print?

        INTEGER P,Q
        P=3
        DO 10 Q=1,27,6
           IF ( (2*P+Q .EQ. 9) .OR. (Q/3 .GT. P))  THEN
              IF (Q .LT. P) THEN
                 PRINT *, 'TILL'
                 P = P + 3
              ELSE
                 PRINT *,'QUIT'
                 P = P + 1
              ENDIF
           ELSEIF ( Q.EQ. 1) THEN
             PRINT *, 'YOU'
              IF (MOD(Q,P) .LT. 1) THEN
                 PRINT *, 'QUIT'
              ELSE
                 PRINT *,'TRY'
              ENDIF
           ELSE
                PRINT *, 'OR' 
           ENDIF
  10     CONTINUE
         PRINT *, 'NOW'
         STOP
         END


Question No. 4. (25 Minutes , 25 Points )

a) Write a subroutine FSWAP that will swap two floating point numbers. The two floating point numbers are to be passed as parameters F1 and F2. Only write the subroutine, not the main program.

b) Assuming the following code:

        REAL X(100)
        INTEGER N
    10  READ *, N
        IF (N .EQ. 0) STOP
        READ *,(X(I),I=1,N)
C Your code starts here


         
         
         


        

C Your code ends here
        GO TO 10
        END
/DATA
        30
        << Data for 30 values of X inserted here  >>
        41
        << Data for 41 values of X inserted here  >>
        0
Write code that will swap the last element of array X with the first, the second-to-last with the second, and so on. Note that N can be even or odd. Call your FSWAP routine, from section 4.a, to swap the elements.

c) Assuming the following code:

        REAL X(100, 100)
        INTEGER N
C       N is the number of rows and number of columns in the matrix
    10  READ *, N
        IF (N .EQ. 0) STOP
        READ *,((X(I,J),I=1,N),J=1,N)
C Your code starts here












C Your code ends here
        GO TO 10
        END
/DATA
        30
        << Data for 30*30 = 900 values of X inserted here  >>
        41
        << Data for 41*41 = 1681  values of X inserted here  >>
        0
Write code that will transpose the array X. The transpose of a matrix reflects each element of the matrix around the diagonal. Assume that X is a square matrix. Again, call FSWAP to swap the elements.
Question 5. (35 Minutes, 38 Points)

Write a program which accepts data lines with simple arithmetic expressions involving +,*,and -, and evaluates them.

For example:

Input           Output

37 + 5          37 + 5 = 42
127 - 14        127 - 14 = 113
4 * 80          4 * 80 = 320
Follow these specifications: Bonus marks for implementing one of these additional features... Additional features might include:


End of Midterm