308-208 - Computers in Engineering - Previous Midterms

# Midterm Winter 1992

1. (10 minutes, 12 points)

What will the following program print? (Remember that integer and real values are printed differently.)
```        INTEGER A, B, C
REAL D, E, G
A = 17./2
B = MOD(22, 7)
C = 12/2**2
D = 5*(19/3)
E = 1+21/(4.5-2.5)
F = A
PRINT *, A, B, C, D, E, F
STOP
END

```

2. (10 minutes, 12 points)

What will the following program print?
```
REAL W, V, U
INTEGER Z, Y, X
Y = 30/2 ** 2/2*2
V = 11/2
X = 23./6
Z = 12-(13/4.)*3
W = 1.1E1 + 1.1E-1
U = 1.1E1 * 1.1E-1
PRINT *, U
PRINT *, V, W
PRINT *, X, Y
PRINT *, Z
STOP
END

```

3. (10 minutes, 10 points)

What will the following program print?
```        I = 10
J = 7
K = 4.8
A = 4
B = 4.2
C = 5.6
CALL FOOBAR(B, C, A)
CALL FOO(J, I, K)
CALL FOO(I, I, 7)
E = C/4
F = B*K
CALL FOOBAR(D, E, F)
PRINT *, I, J, K, L
PRINT *, A, B, C, D
STOP
END
C
SUBROUTINE FOO(I, J, K)
I = (J + K) / 2
RETURN
END
C
SUBROUTINE FOOBAR(A, B, C)
A = (B - C) / 2
RETURN
END

```

4. (10 minutes, 14 points)

What will the following program print?
```        INTEGER I, J(100), K(100), N
INTEGER A, B
READ *, (J(L), L = 1, N)
READ *, (K(L), L = 1, N)
DO 10 I = 2, N
A = K(J(I))
B = K(J(I - 1))
PRINT *, I, A, B, (A - B)
10      CONTINUE
STOP
END
/DATA
7
5  2  1  4  7  6  3
7  6 19 10  3 16 14
/ENDRUN

```

5. (10 minutes, 14 points)

What will the following program print?
```        INTEGER I, J
IF ((I .LE. 0) .OR. (J .LE. 0)) STOP
PRINT *, I, J
20      IF (I .LT. J) THEN
J = J - I
ELSE IF (I .GT. J) THEN
I = I - J
ELSE
PRINT *, 'ANSWER = ', I
GO TO 10
ENDIF
PRINT *, I, J
GO TO 20
END
/DATA
35 16
24 32
60 36
-1 -1
/ENDRUN

```

6. (40 minutes, 38 points)

Write a simple FORTRAN 77 program to accept data in the following format:

```Columns Description                                 Example

1-7             Student ID                                  9512345
11-35           Student Name                        St. Louis, Rejean
41-45           Total Course Assignments (100)    78
46-50           Mid Term also out of 100            67
51-55           Final exam out of 100               73
```

Your program should read a group of records with the above data, terminated by 9999999. For each input record, print the input data, under appropriate headings, and calculate and print the final course mark for each student, all on the same line. The course mark is calculated by counting the assignments for 30%, the midterm for 20%, and the final exam for 50%. The course mark should be printed to one decimal place for each student (e.g. 73.3 for the above example).

At the end of the class list, print the Student ID and Name of the TOP THREE students in the class.

Your program does NOT need to use 2-D arrays nor subprograms.

WRITE your program, with Control Lines, neatly

End of Midterm