# Midterm Winter 1996

1. (8 minutes, 10 points)

What will the following program print?
```
REAL  X, Z, T
INTEGER I, J, K, Y
X   =   4. ** (3 / 2)
Y   =   1 / 2  *  7 / 2
Z   =   SQRT (X ** 2 + Y ** 2)
I   =   (-4) ** (-3)
T   =   X ** Y ** Z
J   =   MOD (INT (X), INT (T))
K   =   IABS (I) + EXP (FLOAT (I))
PRINT *, J, X, Y, Z, I, T
END

```

2. (10 minutes, 10 points)

What will the following program print?
```
INTEGER A,B
DO 22 A  =  17,28,4
DO 33 B  =  1,3
IF (MOD(A,B).GT.B / 3) THEN
IF (A / 6.GE.B) THEN
PRINT *,'HEGEL'
ELSE
PRINT *,'NIETZSCHE'
ENDIF
ELSE
PRINT *,'SPINOZA'
ENDIF
33        CONTINUE
22     CONTINUE
STOP
END

```

3. (10 minutes, 10 points)

What will the following program print?
```	INTEGER A(20,20)
DO  20 I   =   1,N
READ 10,( A(I,J), J  =   1,N)
10	   FORMAT(4I4)
20	CONTINUE
DO 50 I  =  1,N
IP   =   I + 1
DO 50 J  =  IP,N
IW   =   A(I,J)
A(I,J)   =   A(J,I)
50		A(J,I)   =   IW
DO 60 I   =   1, N
60	   PRINT *, (A(I,J), J   =   1, N)
END
/ DATA
4
4   1   2   5
2   3   4   8
5   6   7   10
1   3   4   5

```

4. (7 minutes, 10 points)

The following FORTRAN 77 program contains several (syntax?) errors. Find and circle each error. Write a short explanation for those that cannot be circled!
```

REAL, I, IM
READ 5 IM, W, T,
5    FORMAT (I3, 2F10.0)
DO 20 J   =   1,6
IF (MOD(J,2) EQ 0) THEN
I   =   IM * COSWT +  J
20   CONTINUE
ENDIF
PRINT8, IM, W, T, I
END

```

5. (25 minutes, 30 points)

Write an FORTRAN 77 sub-program (TSTMAT) that accepts a square, two-dimensional array A and its dimension N as input, and determines whether the sum of the elements above the main diagonal is equal to the sum of those below the main diagonal. The main diagonal elements A(i,i), for i = 1, N should be ignored in your calculation.

Write an FORTRAN 77 main program that reads data into a square array, uses the sub-program - TSTMAT, and then prints out the matrix and whether it meets the requirement stated above.

Your program should have a title at the top of a new page. Show the operating system job control lines to run the program. Write your program in the space below and on the reverse of the exam pages as required.

Don't forget good internal program documentation!

6. (30 minutes, 35 points)

The file INF8:CS208.CLASS contains records with the following format
```
COLUMNS	      FIELD				        EXAMPLE
1-7		McGill ID			        8154321
10-30		Last, First names		        SMITH, JEAN
31-60		10 Assignment marks	        10 12 15 .....
61-65		Mid Term mark   (out of 100)	  85
66-70		Final exam mark (out of 100)	  78

```
Using this set of data write a FORTRAN program to perform the following operations.
• Print a suitable heading at the top of a new page and after every 50 records have been read and processed.
• For each record read, print out the input data in a neat form on a single line.
• On this same line include the total of the ten assignment marks, and the overall course grade, which is calculated as follows:
• Scale the total assignments to be 30% (Maximum total 180)
• Scale the mid term to be 20% (Graded out of 100)
• Scale the final to be 50% (Graded out of 100)
• ---------------------------------------------------------
• TOTAL Course Grade 100%
• After every 10 lines of output leave a blank line.
• Your program should be able to handle any number of input records. Show the job control lines you would use for the computer you are using.
• Your program should NOT use any matrices or 2 dimensional arrays.
WRITE YOUR PROGRAM HERE and on the back of the previous page.

End of Midterm