Download Sample Final Exam with Answer Key | MATLAB Programming | COMP 1200 and more Exams Database Programming in PDF only on Docsity!
.1120 Fortran I wnrrfEn 00 SAMPLE FINAL EXAM
V
X
. SAMPLE FINAL EXAM COMPO12OF
i
Page I of
\
Winter 2{XX}
contents!
RAN PR'GRAMMTNG
r (^25) multiple choice, (1 point (^) each) (^) r,,'.i" e 25 Truell'alse, (1 point (^) each) (^) r "f, r (^1) analyze program, (^) (15 points) o I programming problem, (35 points)
Problems 1-25 are Multiple Choice (choose the most appropriate answer). Mark your scan sheet accordingly (^) {lpt. ea.)
l. A compiler
a. is a piece^ of hardware for interchanging different computer
.'b. Piograms - d. r^ r
is a iofttvare-fnigram'.which c^onvert's a pFo$am writteh in a,
Lttigtt level^ language^ into'machinE'code^ instructjons,,'
c. is a low level lang,uage for contioliing? frece df hardware
d. checks the program^ statements for logic errors
a'
- Which of the following is a valid symbolic name in FORTRAN?
a. 4TRAN
b. coMP0120F
-T3Tl-'
d. Memorial^ -^ Dav
e. +40.
I I
I
- The number 8.467988-2 could be.written in a floating-point form (^) as (a)0.8a (b)84.F798 (^) _ _r
(c) 0.08J67e8J
(d) 0.
- (^) What is the value placed in variable (^) A below:
http//web99. (^) auburn. edrlwe b99I p99 (^18) / cse I 2dlsampleJrnal_win00. htm 3/9lAA
r.ttZO po.ttun / WINTER 00 SAMPLE FINAL EXAM.
' a.)
b.)2r
c.) l
d.) 48 --r
- Which one of the following statements is invalid:
Assume the followlng declarations:
REAL :: force, mass (^) = 2. INTEGER :: a,brc = 3,varL,var2,var3 :^ 7'J-,s (^) = 4rpaymenLs INTEGER, (^) PARAMETER :: pl :^8
.{'+
Page2 of 12
Thfa^ar A A - (6 +? *^7 1L
a.) force :^ mass'+ 2.
A C4rIn
- With the following Declarations and Statements indicate the output produced:
CHARACTER{LEN (^) = 30) :: mystr CHARACTER(LEN - 6i :: yourstr
yourstr (^) = "Auburn is whatt(I Love" myStr (^) = yourstr^ //" programming",/,/"^ in Fortran!Tl PRINT *, mystr (^) ; f a.) Auburn
b.) I Inve programmingjnFonran!
--OTnove programming
d.) I Love Auburn!
e.) noffe^ of the aboVe
- Indicats the output of the following Fortran code:
PROGRAM Counterloop
IMPLICIT NONE
fNTEGER :; Sum = 0, LoopVar, FirstValue = 2, Fina1Value = 12,&
Incr = 3
DO LoopVar = FirstValuer FlnalVal-ue, Incr
Sum=Sum+Loobvar
END DO
PRINT *,^ Sum
END PROGRAM Counterloop
of :L^^p- f^'o*th'
().,,),)
5at'l/{ f'+b (^) +ll
1a*a 15 >'l'
a.)
b.) 18
c.) 9 d.) 45
e.)
?uFE+ sl - 3 e.) none of the above
http://web99. auburn. eddwebg g/p 99 | I I csel}O/sampl1fi nal_win00. htm 3/9nA
0120 Fortran / WINTER 00 SAIiIPLE FII{AL EXAM. Page 4 of 12
- Indicate the storage in varaible str2 (^) after the READ ,tut.trr"nt is executed (underbar (^) implies a blank in the answer).
CHARACTER (I,EN
READ"{*,'(A,
Input ti,ne:
A B c Dli F G
(^1) z 5 TI5 6 7
A6,
HI
_*
, canrarvvre^1 t&/^ i^ \
== l-00^ ) EXIT
+L
str]., str2*5' str '), strl.^ st12,^ str
LM
I]
"ii
o{*
l
ili "'
(a) -ABCD
(b) ABC_
,"'J9:9!lr
(d) AB
An affOCaTABLEarrav
fu4gm;sane th9^ agount.ohitrrnoty"niquiryO.py^ a^ prog?g^ f
(b) (^) decreases the execution (^) efficiency of a program (c) (^) can only be used in a SUBPROGRAM
(d) can only be used for single dimensional arrays
16. Which of the following DO loops would read in the test resdlts of 99 students and store
them in an iuray called score? Assume the following declaration:
INTEGER::i
INTEGER, DIMENSION(IOO) ::^ score
(a) i
DO READ * TIT I i
i=i
END DO
].
Ly*
(b)i =
nn
i'= i +
READ *,
IF (i^ >
END DO
1 score (i)^ " lOO ) EXIT
(c)i = 1
DO
READ *,^ score(i)
If -(i^ >=^100 ) EXIT
END DO
{d)Doi=0r 100 .READ *,^ score(i) END DO
htp://web99. airburn.edu/web99/p99^1 8/cse^ I^ 20isample-fi nal*winO0'htm^
319100
^'A120 Fortran^ / WINTER^00 SAMPLE^ FINAL EXAM.^ Page 5^ of^12
t "17. Which of^ the^ following^ control structures would best be used to implement (^) step 2 ofthe
following pseudocode algorithm?
1. Open a file with an unknown number of elements
2. Sum the first 50 elements read from the file
- Output the sum. F (a) (^) a General DO loop
*1Q)g Counter-Controled DO loop
(c) a block IF statement
(d) a sequence ofREAD statements
- (^) What is the value of the varible (^) I after the following (^) statements have been executed I= J: 10
DO-
IF (I^ >:^ J+2) EXIT
J:J- | t
I=I+ 2
END DO
J:J{.*
(a) (^5)
(p)
(c) e ' (^) (d) 10
'o(e) 121
J= r<)
f,-*a'
ltq
J= ol t.?
{s
rlz. tV 4; -)-i
- A mixcd mode expression is orG that has
(a) two or more different operators
f-D (^) I
L'- ll
feI f,jT,
i
- What is the value of X after the (^) following assignment statement is executed?
x=22
(a) st
(b) (^64)
' (^) (d) (^1024) (e) none of (^) these
(b) (^) both constants and variables {l€IgilAast.oneoperato_rwithoperan'tlso'f ttitreTegl-tyiryf^ ,' '{lfnibre (^) tHn c; pairbf^ parenth'eses (e) both variable and function references.
- What is^ the value^ of the expression 1023 + 2/2*4 in FORTRAN? (a) 0. (b) (^0)
http:llwehgg.auburn.edr/web99/p9918/csel20/sample_final_win00.htm 1 tr^ 3l9l
.10120 Forfran / WINTER 00 SAMPLE FINAL EXAM.
(d) (^) I (e) (^) e
PageT of 12
- If a FORTRAN.90 program contains the statements below, which one of the following anay references is proper?
INTEGER:: C(-70:2, -B:-4, -1:5),I
Questions 2C50^ are^ TRUEIFALSE^ questioris;^ Use^ the^ A (true)^ or B^ (false) columns of
your scan sheet to answer problems 2G50(l pL ea.)
A variable^ can have an Integer, Real or (^) Charcter type value. (^) T (^) -/ ilxecutable (^) statements can not be placed anywhere-in the program.' (^) F The associativity of the Additive artitmetic bperations is ri.igtirto:teft. ( The associativity of the Multiplicative artitmetic operations is (^) Left-to-ni4rt. f The parameter list (or argument list) (^) contains all variables used by the function. (^) ,f
In a "call by value' (i.e. the TNTENT(IN) attribute), a. function can
actual para^iter. (^) f
' l'( (^) ,4 ;";^ "^l -^ o/c+,r,'
- The following PRINT statements perform equivalent functions. (^) ;r r
INTEGER, DIMENSION(5) :: arrl- = (/L2,34t56,3,75/,
PRINT *r. (arr1(.1),^
-J
PRINT *,^ arrl
\
In FORTRAN 90, arrays provide^ a method for grouping related information of the same
tvpe. (^) f
Given the FORTRAN 90 statements below, what will be the value of the logical
expression.NOT. A.AND. (^) B -7' T-r
-LOGICAI, :: 'A, B
A = .FAISE.
R = TPrTtr
- The following sections of code are logicaiiy equivalent.
change the'value of (^) an
[,
(a)C(l,I,l) (^) \ *
(b):C(Zttlt+1,3p--:'{
(c) (^) C(l-3,I+3,-t-I) \
(d)rrtfr,I:+:9+n1 '
GfclGff
"33.
. LOGIC.AI, : : A, B
IF (A^ .AND. B) THEN C
ELSE T F
^rIU
END IT
LOGICAL :: A,B
IF (.NbT.^ A^ .OR. .NOT.^ B)^ THEN C
ELSED F tr
END rF
http:I I web99. auburn. ed ul web99 I p99 I 8/cse I 20lsample_ final win0O.htm 3DtOa
^/.0n0 Fortran^ / WINTER^00 SAMPLE^ FINAL^ EXAM.^ Page 8^ of^12
36. A function subprogram'may have another
f
function subprogram as one of its arguments.
- The body of a FORTRAN 90 DO loop
DO I = 1,23,4 ..- /
END Do (^) f (^) i+tl" 2
will execute five times.
- When using the IOSTAT (^) = vuriable option in (^) a FORTRAN (^) READ statement, the value
following the IOSTAT: is the value ofthe last data item in the file.
An anay subscript canbe of type REAL.
f
The array REAL : : X(1:5,2:10) is a table of 9 rows and 5 columns.
tt
An implied DO loop may be used with an Input/Output list and in initialization (i.e. (/.../))
If a programmer wants to enter values for an array with all'ialues on one line, then an
explicit DO loop should not be used to control the READ statement
frf
A dummy or formal argument must be a symbolic narne, it may not be a constant or an
expresston.
- User-defined (^) are intrinsic (^) functions
45. The following program: fi
PROGRAMADDING
INTEGER : :dB,C,SUM,ADD
C:ADD(2,3)
PRINT .^ C*
END
.FUNCTION ADD(A,B)
INTEGER ::ADD,SIJM
INTEGER INTENT (IN)^ :: A,B
SUM:A+B '*
htfp//web99. aubum. edu/web99/p99 I 8/cse I 20lsample-.final_win00. h{m
cl, 'rl^ ,, /
r Alt
| 7' /l^ l')^ t^
t1 z^ )l+
/l'q
),
r
functions
f
3t
'. ltr\
I I J
.t
{,{ } 'l
I i
'i.!iS,- i"/ { t^ r
I i I I t I I It
l'l.
{.r l I I : j I II
'f (^) i: ' (^) ,:r rrit &, i: 1 r-.-,f,? , I
rvli (^) i,l-{i{ii: {:f}:t_:
' t^ ti{1i.".,"i^ ,r"",ri?iit^ iil',:r
lr:r3sf-rjll r-,r;,,r+r)il{r^ I^ :rir''i
r, (^) 1..",:_.1, ,,.. (^) Io ,l ,i.j .'. I t-'.iit--'-' l:-t;q.". t""i,'t (^) iiid -. (^) ' ' :
;- -- '. (^) ",Y. r,
':, '..{l.ti-1'1 iti{Tiljl;ln l.i tq.tin;t;',illr:','Fr.:.il,i i1"5 ,;1..,1;,;ir}!,,^ {i,}tli'e:,'{ l'l
..i"t$i.,};'t-}!.j!|;}l'.i,.'jl:l:i:l,}isr'i":-,.'l;.."fl(lr:c,l^lli1li;irrni:..li'li;sll'xi}r.:".n:itii"lit.'i!|,'1,1,,,.4'1n1l1**.{|
:it -
';"" il r *,ntri3rii"l^ +;i;^ ;';nS'::rJlI^ :;'ri!^ l'iirtj^ :f!iii!{i'tri^ ii'}rj'.!
-{ r.lii,t: i:r-tr.irmrr,.:.1r;}i1{i.1!f; ii'ii,r,tlj,;ll,s't Jll .! , P ! i. *'i,-i,: '-rk i{;,',-lii'li'{l +i,
i4r;, lill,n :t^ -,4^ ..14^ :.ir^ .:iijlr^ i^ :^ fi.6^ -'' {} i^ - i^ -^ i^ .i^ i^ i?j^ 'i,t^ i,;:'^ ':'d^ I^ "''.^ '"i^ I}^ :'r$i.r;li,rt ;:i,
,;jr?'|.],,;liri,l,
f,
i ;tln^ i::i^1 riltl:t',"t{'i^ ;i'"irlttf^ .1{i.tii'i'},;'iufl{
. i;.;$;i I t'it^ ll,' :,,'' iit i I
,t,i i, l, r^ i; iiijil *1^ rll:i^ 1-, "r ;"r1'' ;;l'.,1i^ ;^ t{}^ :i,All'N-}^ I^ flJ^ f'r}{f,',"}'",{?^ :^ i
I I I
t
-.riqftil."* i!t^
j..'11,r.11 (^) ;{rB'';$i:"i1.vr'JJ},; tr',trrli;r'''i,,'r11."'i t;!".i
r*f t
t t I 1rI
.t^ t-
J1.r;,! r).r41"-1^ jtcl,rl
./10120 Fortran / WINTER 00 SAMPLE FINAL EXAM.
PRIN? *I^ IENTER THE DIMENSIONS OF THE I4ATRIX:I
READ */^ ROWS,.COLS
I * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
DO I = l-, ROWd
DO J=!, COLS
K=I/,J'
MATRIX (I,,])^ = FacLorial (K)
END DO
RESULTING MATRIX ELEMENTS
'DISPI;AY OT^ MA?RIX^ RESULT^ '
1r COT,S
' (MATRIX(I,J)^ , -I = 1,^ ROWS)
CONTA]NS
INTEGER (^) FUNCTION FACTORIA1 (K)
INTEGER, INTENT (IN) :: K
INTEGER
L FACTORIAJ,=
Page 10 of
it
END DO "J DISPLAY THE PRINT * I)D TNIT *^ t NAT_ uwu- PRINT * END DO
DO L=1rK
FACTOR IAL= FACTOR I A^ L*^ I
END DO END (^) FUNCTION FACTORIAL
END PROGRAM MAIN i,
OUTPUT HERf,:
Piogramming Problem (35^ pts)^ F
I
9t* a^ DO loop FUNCTIONs^ and/or^ SUBROUTINES^ to perform^ the^ following:
. (^) 'Read successive test scores from an input file TEST.DAT (see (^) below for data in file) and place
the values into an array. Assume that no more than 5fl) values will ever need to be read.
Terminate reading using the IOSTAT clause. The test scores will be numbers beiween 0.
and 100.00 inclusive.
. (^) Use zuNCTION and/or STIBROUTINES Subprograms to calculate the following from the
anay (if^ you^ dont^ use FUNCTIONS^ and/or SUBROUTINES you^ will loose 5 points)
. (^) Find h'ow mnny scores greaier (^) than 9A.0A have occurred . (^) Find how many scores smaller thah 60.00 have (^) occurred
r (^) Output the minimum, moximum aeerage value rutmber of scores greuter (^) than 90.00 (^) and
number af scores smnller than 60:A0 found.
Input File: TEST.DAT (one value per,line)
http:I I web99. auburn. (^) eddwebg g/1i99^ I 8/cse I 20lsample*final_win00. htm
f.?{'l
r&
::::"ffi;::,o imp,emen,,n",.ffi,*#
\
array (1I^ you^ oon'r^ use ruNUrlr.JND^ angor JUl'I(uu llNt
\ 6 Fiird the minimum valuein the *ru, * \ YrinA^ the^ maximumvaluein^ the^ uoiy^ f^ ^ t^r) \ r Find the average value of the valuei read from tne (^) fleY
),/;r-1:o-
O r'r^
Y
co lu (^) /^n (^5)
/4w 1
/a* 14vezz1*
(. )q\
3/9/