308-208 - Computers in Engineering - Previous Midterms

# Midterm Winter 1994

1. (10 min., 10 points)

Classify each of the following, according the rules of FORTRAN 77, by placing each one under the most appropriate column in the table. Assume no explicit declarations.

```PI      PRODUCT   AND      TRUE      DO 7 K 12.25
MANY   .OR.       .FLSE.   *SUM
1ZERO   IJK       3.0      123,000   0.0001
N       \$1.90     -445     .GT.      AREA
```

Categories:

• Valid Fortran REAL Variable
• Valid Fortran INTEGER Variable
• Valid Fortran INTEGER Constant
• Valid Fortran REAL Constant
• Valid Fortran LOGICAL Operator
• Valid Fortran RELATIONAL Operator
• Not Valid in Fortran

2. (10 min., 12 points)

What will the following program print?
```        A  =  5.1E1 + 4.8E2
I  =  MOD(78,5)
B  =  57/7
C  =  50./3
K  =  C
J  =  (10.0/4)**2
PRINT *,I,J,K,A,B,C
END

```

3. (10 min., 12 points)

What will the following program print?
```

INTEGER I,J,X,Y,K,L,P,Q

I  =  3.9
J  =  5
X  =  1.0
Y  =  -2.0
K  =  I/J
L  =  MOD(J,I)
P  =  X+Y/2.0*X
Q  =  I+J/2.0*X
A  = 2**(2+1)/6+ 1.1E1
PRINT *, I, K, L, Q, P, A
STOP
END

```

4. (10 minutes, 15 points)

What will the following program print?
```
INTEGER I,J
DO 30 I  =  21, 28, 3
DO 20  J = 1,2
IF (MOD(I,(J*2)) .GT. ((J+1)/3)) THEN
IF (I/19.GE. J) THEN
PRINT *,  'BANANA'
ELSE
PRINT *, 'APPLE'
ENDIF
ELSE
PRINT *, 'ORANGE'
ENDIF
20       CONTINUE
30    CONTINUE
STOP
END

```

5. (10 minutes, 15 points)

What will the following program print?
```

REAL  U, Q, KK, NN, INT1, INT2
INT1 = 3.00
INT2 = 7.00
NN = 2.80
KK = 3
U = 3.20
Q = 7.80

TOTAL = INT1 +  INT2 + KK+ U + Q + NN
PRINT *, 'BEGIN --> ',  INT1 , INT2 , KK , U , Q , NN
PRINT *, TOTAL
CALL SUB1(INT2,TOTAL)
CALL SUB2(KK,TOTAL)
CALL SUB2(INT2,KK)
TOTAL = U + Q
CALL SUB1(TOTAL,INT2)
CALL SUB2(INT2, INT1)
PRINT *, 'END ----> ', INT1 , INT2 , KK , U , Q , NN
PRINT *, TOTAL
STOP
END

SUBROUTINE SUB1 (T1, T2)
LOCAL = T1
T1 = T2
T2 = LOCAL
RETURN
END

SUBROUTINE SUB2 (T2, T1)
T1 = T2
RETURN
END

```

6. (40 minutes, 36 points)

Write a FORTRAN 77 program that reads 20 records, each record containing a student's name and final score for a course. In each record, the name is in columns 1-17 and the score is an integer in columns 21 - 22.
• Print out each student's name, mark, and the message 'PASSED' if the score is greater than 65, or 'FAILED' if the score is less than or equal to 65.
• Find and print the best student's name and mark. (Assuming that there is only ONE top student).
• Find out and print how many students passed the course, and how many failed it.
• Show the control lines used to run your program.