Study Guides (238,185)
COMP 208 (1)
Midterm

# comp midterm2.pdf

14 Pages
237 Views

School
McGill University
Department
Computer Science (Sci)
Course
COMP 208
Professor
Nathan Friedman
Semester
Fall

Description
Make sure the version number is marked on your scantron sheet. This is version 1 McGill University COMP 208 -- Computers in Engineering Mid-Term Examination Thursday, October 15, 2009 2:35 – 4:00 P. M. Faculty standard calculators allowed. Grading: Question Possible Points 1-10 3 marks each 11-15 4 marks each 16-25 5 marks each Total 100 Computers in Engineering 1 of 14 October 15, 2009 Midterm test Version 1 Question 1 The Fortran statement X = Y means: a) The value of X is the same as the value of Y b) The memory cell X is the same as the memory cell Y c) The value stored in Y should be copied to X d) The value stored in X should be copied to Y e) None of the above Question 2 The term “source code” refers to. a) The program coded in machine language that the computer can execute b) The instructions in the CPU that is next to be executed c) The program written in a high level language that the compiler translates d) The translation produced by the compiler. Question 3 The following statement will print the value of I if it is equal to 2 or 3. If the value of I is anything else, it will not print anything. IF (I == (2 .OR. 3)) WRITE (*,*) I a) true b) false Question 4 In FORTRAN all arithmetic operators at the same level of precedence are evaluated from left-to-right: a) true b) false Question 5 What is the result of evaluating the expression 4/3 == 4/4? a) True b) False c) This is not a valid expression Computers in Engineering 2 of 14 October 15, 2009 Midterm test Version 1 Question 6 Consider the following code segment. logical a1, a2 a1 = .TRUE. a2 = a1 .AND. 3 < 7/2 The value assigned to a2 will be: a) true b) false Question 7 What is the result of evaluating the expression 14 – 6 / 6 – 2 a) -1 b) 2 c) 11 d) 13 e) 15 Question 8 What is the Fortran expression 2**2**3*2 equal to? a) 64 b) 128 c) 512 d) 4096 512 e) There is an error since 2 is too large Question 9 Suppose a program opens a file which is designated in the OPEN statement as UNIT = 13. If the programmer wants to read from the file, the read statement must be of the form READ (*,13) … a) true b) false Question 10 The following Fortran statement will print 123.45. write (*,"(f5.2)") 123.45217 a) true b) false Computers in Engineering 3 of 14 October 15, 2009 Midterm test Version 1 Question 11 What decimal number is represented by the binary 11010000? a) 416 b) 208 c) 322 d) 156 e) None of the above Question 12 What is the output of the following program? PROGRAM Mid2 IMPLICIT NONE INTEGER :: A,B REAL :: X,Y A = 3.1415 Y = A X = 2/3 B = 3*X WRITE (*,*) A, B, X, Y END PROGRAM Mid2 a) 3.1415 2 0.6667 3.1415 b) 3 0 0. 3. c) 3.1415 3.1415 0.6667 2. d) 3 3. 0. 0. e) None of the above Computers in Engineering 4 of 14 October 15, 2009 Midterm test Version 1 Question 13 What is the output of the following program? PROGRAM mid INTEGER :: x,z REAL :: y x=10 y=10.5 z=y IF ( (x == z) .AND. (x == y) ) THEN WRITE(*,*) "One" ELSE IF ( z==y ) THEN WRITE(*,*) "Two" ELSE IF ( (x==z) ) THEN WRITE(*,*) "Three" ELSE WRITE(*,*) "Four" END IF END PROGRAM mid a) One b) Two c) Three d) Four e) The program has a syntax error Question 14 Suppose the integer variable, is set by M=2000. In order to get the output ##***2000*** (where # is used to indicate a space), the code should be a) WRITE(*, "('2X','***',I4,'***')") M b) WRITE(*, "(2X,'***M***')") c) WRITE(*, "(3X,'***2000***')") d) WRITE(*, "(2X,'***',I4,'***')") M e) WRITE(*, "('2X','***',M,'***')") Computers in Engineering 5 of 14 October 15, 2009 Midterm test Version 1 Question 15 What is the output of the following program? PROGRAM midterm IMPLICIT NONE INTEGER :: a,b,c,i a=4 b=8 do i=1,10 if(a==b) EXIT a=a+1 b=b-1 end do c= b / (a+1) if(c<=0) THEN write (*,*) "The condition is true" STOP else write (*,*) "The condition is false" END IF Write (*,*) "The program has terminated" END PROGRAM midterm a) The condition is true The program has terminated b) The condition is true c) The condition is false The program has terminated d) The condition is false e) The program has terminated Computers in Engineering 6 of 14 October 15, 2009 Midterm test Version 1 Question 16 What is the output of the following Fortran program if the values input are: 1 2 3 4 5 6 7 8 9 10 11 12 program midterm implicit none integer :: d, w, h integer :: table (2,3,2) read (*,*) (((table(d,h,w), w=1,2),h=1,3),d=1,2) write (*,*) table (2,1,2) end program midterm a) 8 b) 9 c) 2 d) 3 e) 12 Question 17 What is the output of the following program? PROGRAM midterm IMPLICIT NONE INTEGER :: i, inc=5, j j = 0 DO i = 1, 100, inc IF (MOD(i, 2) == 1) j = j + 1 END DO WRITE(*,*) j END PROGRAM midterm a) 10 b) 11 c)
More Less

Related notes for COMP 208

OR

Don't have an account?

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Join to view

OR

By registering, I agree to the Terms and Privacy Policies
Just a few more details

So we can recommend you notes for your school.