Docsity

Multiple Choice Questions on Program Functions - Project 5 | ECE 3331, Study Guides, Projects, Research of Electrical and Electronics Engineering

Toggle sidebar
bg1
Part 4. FORTRAN
A. Select the best answer to each of the following concerning standard FORTRAN 77
and circle your choice.
1. A FORTRAN statement is continued to a second line by
a. putting a ‘C’ in column one of the second line
b. putting a ‘-’ at the end of the first line
c. putting a ‘&’ in column six of the second line
d. setting the margins of the editor to 72 columns
2. In the absence of parenthesis, which of the following operations
has the highest precedence.
a. +
b. *
c. .AND.
d. .LT.
e. .NOT.
3. In a correctly formed IF block
a. the ELSE clause is optional
b. the ENDIF is optional
c. exactly one of the IF or ELSEIF conditions is true during execution of the block
d. the condition is an arithmetic expression
4. A DO loop
a. begins with a DO and ends with an END statement
b. always executes the statements in the range at least once
c. may be executed prematurely with a GO TO statement
d. must include a statement to increment the index
5. The statement SUM = SUM+SCORE
a. reads a new value for the variable SCORE
b. reads a new value for the variable SUM
c. expresses the mathematical identity that SCORE = 0
d. increases the value of SUM by the value of SCORE
e. changes the values of both SUM and SCORE
6. A dummy argument is
a. a variable in a program
b. an argument between stupid people
c. written in parenthesis in a CALL statement
d. written in parenthesis in a SUBROUTINE statement
e. allowed to be a constant
pf3
pf4
pf5
pf8

Partial preview of the text

Download Multiple Choice Questions on Program Functions - Project 5 | ECE 3331 and more Study Guides, Projects, Research Electrical and Electronics Engineering in PDF only on Docsity!

Part 4. FORTRAN

A. Select the best answer to each of the following concerning standard FORTRAN 77 and circle your choice.

  1. A FORTRAN statement is continued to a second line by a. putting a ‘C’ in column one of the second line b. putting a ‘-’ at the end of the first line c. putting a ‘&’ in column six of the second line d. setting the margins of the editor to 72 columns
  2. In the absence of parenthesis, which of the following operations has the highest precedence. a. + b. * c. .AND. d. .LT. e. .NOT.
  3. In a correctly formed IF block a. the ELSE clause is optional b. the ENDIF is optional c. exactly one of the IF or ELSEIF conditions is true during execution of the block d. the condition is an arithmetic expression
  4. A DO loop a. begins with a DO and ends with an END statement b. always executes the statements in the range at least once c. may be executed prematurely with a GO TO statement d. must include a statement to increment the index
  5. The statement SUM = SUM+SCORE a. reads a new value for the variable SCORE b. reads a new value for the variable SUM c. expresses the mathematical identity that SCORE = 0 d. increases the value of SUM by the value of SCORE e. changes the values of both SUM and SCORE
  6. A dummy argument is a. a variable in a program b. an argument between stupid people c. written in parenthesis in a CALL statement d. written in parenthesis in a SUBROUTINE statement e. allowed to be a constant
  1. A function subprogram a. is limited to a single statement defining the function value b. is invoked with a CALL statement c. cannot use the same variable names as the main program d. contains all of the declarations necessary to compile it separately from the main program
  2. FORTRAN 77 does not allow subscripts in array references to be a. real constants b. negative integer constants c. integer variables d. zero e. integer expressions
  3. Which of the following is TRUE concerning subprograms? a. When an array is used as a dummy argument, all of the values in the actual argument must be copied from the actual argument into the dummy argument b. Since there is an automatic type conversion, an integer actual argument will be automatically converted to a real dummy argument if required c. The source code for a subprogram must be completely before the main program d. A subprogram should always contain a STOP statement e. none of the above are true
  4. Which of the following is TRUE? a. If a formatted WRITE is used to print an array and the end of the FORMAT is reached before all elements have been written, an execution error will occur. b. An implied DO-loop may be used to calculate the sum of the elements of an array. c. When a two-dimensional array name appears in a READ without subscripts, the entire array is input, one row at a time. d. Real values have a greater range than integer values.
  5. Which of the following is NOT a valid FORTRAN 77 data type? a. boolean b. character c. integer d. real e. complex

B.(10pts)Show the output that would be produced by the execution of the

following.

PROGRAM XMAS REAL FUNCTION TREE(X)

REAL A,B,C,X,Y REAL X,A(3),Y

DATA A,B,C,X,Y/1.,2.,3.,4.,5./ DATA A/3.0,-4.,1.0/

CALL DECK(X,C,A) Y = A(3)

WRITE(6,*)A,B,C DO 10 I = 2,1,-

STOP Y = Y*X+A(I)

END 10 CONTINUE

SUBROUTINE DECK(A,B,C) TREE=Y

REAL A,B,C,X,Y RETURN

X = TREE(A) END

Y = TREE(B)

IF(X*Y.LT.0.)THEN

C = (A+B)/2.

ELSE

C = (A-B)/2.

ENDIF

WRITE(6,*)X,Y

RETURN

END

output:

C.(5 pts each part)Write the FORTRAN statements required by each of the

following. Do NOT write complete programs. Unless otherwise indicated,

assume variables have been appropriated declared and assigned values.

  1. Assign to x the value of 3 2 1 1 5 a b c d  ^ n   . Assume that a,b,c,d and x have been declared as REAL, that n has been declared as integer, and that a,b,c,d, and n have previously been given values.
  1. Assign to bob the sum of the elements in the odd-subscripted positions of the real, singly subscripted array betty which has n elements. Assume bob, betty and n have been properly declared and betty and n have been assigned values. (for example, if betty = {3.1,2.4,4.6} then bob should be equal to 7.7.) 3.If the integer K is evenly divisible by 3, and the real A is strictly between -1 and 1, write “you win”; otherwise if A is greater than 1 write “I win”, and if none of these are true, write “we both win”. 4.Count the number of times the value P occurs in the N row by M column array A. (P and A have been declared REAL, N and M have been declared INTEGER, N, M and A have all been assigned values.)

E.(10pts)SUBROUTINE Subprogram

The elevations at various locations in a region may be stored in a grid (two-dimensional array) such as 5039 5127 523 8 5310 516 7 529 0 556 0 549 0 514 2 5021 4920 5229 538 4 5839 486 2 5023 513 4 5411 5476 5178

..... ..... ..... ..... A “peak” is identified as a location that has lower elevations all around--by which we mean directly above, directly below, directly to the right, and directly to the left. Thus in the above grid there are three peaks: row one,column 4; row two,column 2; and row three,column

  1. The “tallest” peak is 583.9. Write a FORTRAN subroutine PEAK(NR,NC,GRID,NP,TALL) that will examine a NR row by NC column array GRID of elevations and determine the number of peaks (NP) and the height of the tallest peak (TALL). NR,NC, and GRID will be furnished by the calling program. Your subroutine should not contain any READs or WRITES. You may assume the argument corresponding to GRID has been dimensioned as 25 by 25 in the calling program.

F.(15pts)Main Program

Suppose the (4 digit) posting IDs and corresponding grades on project 5 in ENGI 1331 have been stored in a data file named GRDE.DAT, with one posting ID and corresponding grade per line. Suppose further that they have already been sorted so that they are in order of increasing posting ID. Write a complete FORTRAN program (omitting comments) that will read this information and produce a printed output showing the ID’s and grades in a tabular form such that there are four columns of output pairs. For example, if GRDE.DAT contained: 1204 85. 1215 95. 1220 60. 1345 40. 1391 100. 1442 75. 1533 30. 1574 80. 1614 90. 1843 63. Then the output should be: PID P5 PID P5 PID P5 PID P 1204 85. 1345 40. 1533 30. 1614 90. 1215 95. 1391 100. 1574 80. 1843 63. 1220 60. 1442 75.