Q1-15. LAST Name ________________________
Q16
0 !!
First Name _______________________
Q17
0 !!
McGill ID _______________
Q18 McGill University Computers in Engineering COMP-208A Final Exam Friday, 10th December 2004 2:00 p.m. – 5:00 pm
Q19 ∑
Examiner: Prof. G. Ratzer Associate Examiner: Prof. M. Newborn Faculty CALCULATORS are allowed. This is a closed book, multiple-choice exam to be answered using the mark sense sheets for Questions 1 to 17. Select what you consider to be the BEST answer of the answers provided for each of these questions. The multiple-choice questions may be subjected to the McGill Security Computer Monitoring program that analyzes for possible cheating. Questions 1 to 15 are worth 4% each of this exam. Questions 18 and 19 (nominally worth 20% each) are to be written in the exam booklets provided. This exam paper and the booklet must be returned. This exam consists of 11 pages. Crib sheets are NOT allowed. QUESTION 1. What is the output of this FORTRAN 90 program: program Q1 implicit none integer :: I,J,K real :: A,B,C A = 2.7E1 + 5 B = 32/7 C = 32.0/7 I = 2.2 + MOD(27,5) J = 27/4*4+2-1*2 K = C write(*, *)I,J,K,A,B,C stop end program Q1 A.
B. C. D. E.
4 24 4 32. 4 27 3 5.21 4 24 5 29.0 7 27 3 29.0 None of the above
Computers in Engineering 10th December 2004, 2-5pm
4.0 3.0 5.0 3.0
4.57143 3.0 5.57143 3.0 - 1 of 11 Pages -
COMP-208A Version 1
QUESTION 2 What is the output of the following program? PROGRAM Q2 IMPLICIT NONE INTEGER :: I,J,K J=0 DO I=1,5 J=J+2 K=J+4 END DO DO I=1,K J=J+1 END DO WRITE(*,*) I,J,K STOP END PROGRAM Q2 A. B. C. D. E.
15 115 14 15 15 14 14 24 15 14 24 14 None of the above
QUESTION 3. What ordered set of letters is output by the following program? PROGRAM Q3 IMPLICIT NONE REAL :: A,B,C INTEGER :: I,J,K
A= (9/4)*1.0 + 2 B= 2 C= 8/2*2-4 J= 9.99 K= 24/2 Computers in Engineering 10th December 2004, 2-5pm
- 2 of 11 Pages -
COMP-208A Version 1
DO I=1, 2 IF (K < J) WRITE IF (K > J) WRITE END IF END IF
THEN (*,*) “B” THEN (*,*) “I”
IF (I > B) THEN WRITE (*,*) “N” ELSE WRITE (*,*) “G” END IF
IF (J /= C) THEN WRITE (*,*) “I” ELSE WRITE (*,*) “O” END IF END DO
STOP END PROGRAM Q3 A. B I N G B. G I G I C. I G I I D. I G I I E. None of
O N I G I the above
QUESTION 4. What is the SECOND LINE of output of the following FORTRAN program? program Q4 implicit none integer :: one, two, i, temp real :: ph, oph, tph, er 1 format (I2, ': ', I5, ' ph: ', F7.5, ' er: ', F7.5) i = 3 one = 1 two = 2 ph = 1. tph = (1+sqrt(5.))/2 ph = two/(1.*one)
Computers in Engineering 10th December 2004, 2-5pm
- 3 of 11 Pages -
COMP-208A Version 1
er = tph-ph do temp = two two = one + two one = temp oph = ph ph = two/(1.*one) er = tph-ph write(*,1) i, two, ph, er i = i + 1 if(oph == ph .OR. ph < 0. .OR. i == 8) exit end do end program Q4
What is the SECOND LINE of output of the above program: A. 3: 3 ph: 1.50000 er: 0.11803 B. 6: 13 ph: 1.62500 er: -.00697 C. 5: 8 ph: 1.60000 er: 0.01803 D. 4: 5 ph: 1.66667 er: -.04863 E. None of the above
QUESTION 5. What is the output of the following FORTRAN program when the following input is used? 2003 ← This is the input PROGRAM Q5 IMPLICIT NONE INTEGER :: A, B(8) READ(*,*) A CALL MYSUB(A,B) WRITE(*,*) B STOP END PROGRAM Q5 SUBROUTINE MYSUB(A,B) IMPLICIT NONE INTEGER :: A,B(8),I DO I=8,1,-1 B(I)=MOD(A,5) A=A/5 END DO Computers in Engineering 10th December 2004, 2-5pm
- 4 of 11 Pages -
COMP-208A Version 1
RETURN END SUBROUTINE MYSUB A. B. C. D. E.
0 0 0 3 0 0 0 3 0 1 1 2 3 0 0 1 None of
0 4 1 0 0 0 3 0 the
1 3 0 3 0 3 0 0 above.
Computers in Engineering 10th December 2004, 2-5pm
- 5 of 11 Pages -
COMP-208A Version 1
QUESTION 6. What does the following C program output? #include <stdio.h> void i2b (int in, char s[]); int main (void) { char s[33]; i2b (120, s); printf ("%s\n", s); return 0; } void i2b (int in, char s[]) { int i, f; s[33] = '\0'; f = 1; for (i = 0; i < 32; i++) { s[31 - i] = (in & f) ? '1' : '0'; f