Sample Exam 2 Solutions - Matlab Programming | COMP 1200, Exams of Database Programming

Material Type: Exam; Class: Matlab Programming; Subject: Computer Sci & Software En; University: Auburn University - Main Campus; Term: Unknown 2000;

Typology: Exams

Pre 2010

Uploaded on 10/12/2009

koofers-user-5zk-2
koofers-user-5zk-2 🇺🇸

4.5

(2)

10 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
I
EXAM2 Winter 2000 Page 1 pf7
by the following PRINT statement [4 ptsJ:
pRrNT' (1X, F6.0, Ttzt F6.2) "I204.899.603.588
-i- r 29tl i - - - -{e o 3 ,51[-
Ll2 3 4 5 6 7 8 e I 1'l I i I : +'l t"i
2. What is the output produced by the following statement [4 pts]:
(1X, 13, 4X, 14) ') 2r799, 9902
3. What is the output produced by the following statement[6 pts]:
11'lvi'{
' (1X, 2(lX, F6.3), 13) ') 33.0559, 970.5588, 299
4. With the input given, what are the values placed in the followirig variables when the READ
statement is executed? Show answers in table at.top of next page [10 pts].
WRITE (*,'
,l
- B t"xl.
1l2 3 4l5
1
llq 0 2
E 7 Ble l l T T T T T T 112 2
s72345618901
aa bl -lv t nr ry{e711- - -
6 7 Blell 1 1 1 1 111 t 717 2 2
0 7 2 3 4 5 6 7 8.9 0 1
WRITE (*,
I 11 ?
-l -l /- -' :-
112r3 4 s
REAL ::
INTEGER
READ (*,
rzJq ;;
ZZ
78
Var1, !ar2, Var3, Var4
:: Var5
' (F5.2, 285.2, F8.3, 13)') !arL, t'larZ, Var3,
zl'^ -o': :fs o . a z(^ 4 o'7 2 2" .i^'e,r[
_l*_ l_____l_ ___t_ll__l_l
s\6 7 8 9 111 1 1 1 1l\1 1 1 1 2 2 212112 2t2^
o'L 2 3 a sl\e 7 I 9 o L z':lq s'e'\
Yar4, Yar5 i
."t t," . t
lr
lGt*
WTT
Yar2 -D-.j.\
Var3 47,oL
Ya'r4 rlD. l}?
fr1
%(\
Xin
"\ 4\-
liL
http:
I
/ web99. auburn. edu/web99 I p99 18/cse 1 2Olsamplex2. htm
COMP 120 Fortrnnr Winter 2000
I l('P
SAMPLE BXAM2
l. What is the output
--.'--xl
\^(\,#i*rn
k--!''J?#"^^'
pf3
pf4
pf5
pf8

Partial preview of the text

Download Sample Exam 2 Solutions - Matlab Programming | COMP 1200 and more Exams Database Programming in PDF only on Docsity!

I

EXAM2 Winter 2000 Page^1 pf

by the following PRINT statement [4 ptsJ:

pRrNT' (^) (1X, (^) F6.0, Ttzt F6.2) "I204.899.603. -i- r^ 29tl^

i

      • -{e

o (^3) ,51[- Ll2 3 4 5 6 7 8 e I 1'l I i I : +'l t"i

  1. (^) What is the output produced by the following statement [4 pts]:

(1X, (^) 13, 4X, (^) 14) (^) ') 2r799, 9902

  1. What is the output produced by the following statement[6 pts]:

11'lvi'{

' (1X,^ 2(lX,^ F6.3),^ 13)^ ') 33.0559, 970.5588,^299

  1. With (^) the input given, what are the values placed in the followirig (^) variables when the READ statement is executed? (^) Show answers in table at.top of next page (^) [10 pts].

WRITE (*,'

,l

  • 1l2 B^ t"xl. 3 4l

1 llq 0 2 E 7 Ble l l T T T T T T 112 2 s

aa bl (^) -lv t nr (^) ry{e711- (^) - - 6 7 Blell 1 1 1 1 111 t 717 2 2

WRITE (*,

I 11?

-l 112r3 -l /-^ -' 4 :-s

REAL ::

INTEGER READ (*,

rzJq ;;ZZ

Var1, !ar2, Var3, Var

:: Var

' (F5.2, 285.2, F8.3, 13)')^ !arL,^ t'larZ,^ Var3,

zl'^ (^) -o': :fs o. a (^) z(^ 4 o'7 2 2" .i^'e,r[ l* (^) l_____l_ ___t_ll__l_l s\6 7 8 9 111 1 1 1 1l\1 1 1 1 2 2 212112 2t2^ o'L 2 3 a sl\e 7 I 9 o L z':lq s'e'\

Yar4, Yar5 i

lr^ ."t^ t,"^.^ t

lGt*

WTT Yar2 (^) -D-.j.\

Var3 (^) 47,oL

Ya'r4 (^) rlD. (^) l}?

fr

%

(
Xin liL^ "^ 4-

http:I (^) / web99. auburn. edu/web99 I p99 18/cse (^1) 2Olsamplex2. htm

COMP 120 Fortrnnr Winter 2000

I l('P

SAMPLE BXAM

l. (^) What is the output

--.'--xl

^(,#i*rn

k--!''J?#"^^'

EXAM2 Winter (^2000) Page2 af

var5 (^) ll gb

  1. With the input given, (^) wha les when the (^) READ statement is executed (^) [9 pts]?

With the input given, what are thb values placed in the following variables when the READ

statement is executed (^) [9 ptsJ?

CHARACTER(LEN: 10) :: Strl8, Str2, Str33, (^) Str4* READ('*,'(Al1,T16 (^) , \ ll, M.,1, (^) A19)') Strl, Str2, Str3,Str

cHanactsn(LEN (^) = 10) :: $trt-

CHARACTER(LEN - 3) :: Str2, Str

READ (*;'(A, X, A8, T23, A2)') Str1, SLr2, Str3 r

r- I ll I ll / ll I rNpur LrNE: A B C D E F G H r ;lxlr M (^) N O p^ Q R slh u vlw x v z _i (^) _[l L__l____ ,r 2 3^4 s 61 I 9 11111 1 l 1 t 1 1 Llz 2 212 2 2 2 ol1l2 ll 3 4 s 6't (^) B slo r 213 4 5 6

Rut*s! |^

' \

Field width (i.e A7, field width - 7) characters are read (^) from input line (remember (^) tf no frel-d width is speci-fied r-t is equal to the amount of storage for the vareable) tf freld width > length of character vanabLe - right justify (i.e 4. truncate from left) If field wldth < lenqth of qharacter^ variable - Ieft justify (add blanks !o .rest of storaqe)

r\Jl lnvenv

uav t- { (^) - J 11 1 1^1 2 2 2 2 2 2l-^ -^ -l

15 7 I^ e 0^12 3 4^ 5l

I t 1 ?'3 4 5 6 7 I 9 r'J. I 1 L 1 1 1^1 ,_:. 012'34s6?B

3rd tiD€: \1)'/|-S/

--I--t 213 4 5 6 7 I -:-- 9 1 I 1, L 1 I 1

| 9L234s

4thIiLDe: (^) ITHE^ lr KEY (^) To SUCCESI tl \43T5675ETTTTTTTTTTI

r 0!234 56789 |

Irttpl lweb99.auburn.edr/web99/p99 1 8/cse 1 20lsamplex2.htm

Variable

3t6ta

LE EXAM2 Winter 2000

OPEN (^) {UN]T - i2, FiLE (^) = F1.LeName2. STA.TUS : (OtD.^ ACTION TOSTAT (^) = OpeDSLatus) iF (^) {Openstatus ]> O) StoF t*,{t error opentrng ft1e2 t+\t( OPEN (^) {UNIT :^ 13, FILE (^) = FafeName3, STATUS (^) = "REPLACE",&

. P.qge^4 af^7

fF (^) {Openstatus > 0) STOP n++ error--opening frfe3 ****"^ IOSTAT':.-.'^ OFensLatrs) o i.t}{ g DO READ {UNIT (^) = 11r lMI (^) = *,^ JOSTAT (^) =.InputStatusl} larl READ TUNIT = 72t FMi (^) = *.^ IOSTAT: lnputstatus2) Var

  • fF (^) {fnFutstatusL > 0) SlOp i****^ Jnput Error ****r . IF^ ilnputstalus2 >^ 0)^ STOP^ trd*4^ Input Error ****( , 1F (Jnputstatus.l IF <^0 .OR.^ Inputstatus2 <^ 0)^ EXIT {Var1 > Varz) I4RITE {UNIT^ THEN EtSE^ :^ 1-1, FMI^ =^ )^ Varl WRIIE (^) {UNIT = 13, FMI (^) = )^ Var END IF IF (^) {Va!1 > Varln) THEN Varlm (^) = Vari END IF ' IF (Var2 < Var2m) THEN Var2m (^) - Var END IF E}ID DO ctosEill) ctosE(i2) MW]ND 13 READ (UNIT (^) = 13, Flat (^) = .^ IOSTAT (^) = Inpurstatus3) Var IF (^) {Inputslalus3 > 0i STOP rr,la^ Input (^) Error rr' IF (Inputstatus3 < O) EXIf -Count=Countfl^ VirlF=1/ar3m+Var ' EHD DO PRfNT *,"Var1m^ = n,Var-lm,. Vat2m= n,Vat2m,d Average Var3 (^) = ", & CIoSE(UNIT (^) = 13) END FROGP.}I'1 (^) files

Var3n/REAt (Caunt)

  1. Answer the True/False questions related with the following Fortran code [6 pts total]-

PROGRAMAPTobIem

IMPLICITNONE

INIEGER :: var1, var2, var3, OpenStatus, (^) Readsbtus

OPEN (UMT (^) = 15, FILE = "INPUT.DAT., SiafUS (^) = 'OLD-, IOSTAT (^) = Opensratus)

IF (Openstatus^ >^ 0) STOP (^) "Error Opening File'

DO

CALL Readlnf{ 1 5, ReadStatus, varl, var2ivar3)

IF (Read8tatus < 0) EXIT

WRITE (t,1F4^ 0), ADVANCE (^) = -NO")^ Calc(varl, var2, var3)

ENDDO

CONTAINS

RINCTION Calc (in1, in2, in3)

REAL. Caic

http.l lweb99. auburn.edul web99 (^) lp99 I 8/cse I (^) 2Olsamplex2.htm 316t

LE EXAM2 Winter 2000

nriscsn INTENT(iN):: inl, in2, in

INTEGER: retValue

IF (ml >^ irt2 AND. in1 > in3)

THEN retValue = rnl

E["SE IF (in2 >^ inl AND. (^) in2 > in3) (^) TIIEN

retValue - rn

ELSE

retValue = in

ENDIF

Calc = retValue

ENDFUNCTIONCalc

SUBROUnNE Readlnfo (FileUnit,^ **o, in1, in2, in3)

INTEGE& INTENT(IN)'. FileUnit

INTEGER" INTENT(NOffi) : ReadStatus

INTEGER, INTENT(OUT)': ml, in2, in

READ (UNIT^ = FileUnil, FMT = i,IOBTAT^ = ReadStatus) inl,in2,in

IF (Readstatus > 0) STOP {at^ Read Enor *rn

END SUBROUTINE Readlnfo

ENDPROGRAMAPTobIem

t What is the output prodrrced by the followiag prograrn with thi input given [12 pts] Input File:IN.DAT 85.3 37.2 9s.8 17.

16.2 99.4 27 I 18.

Page 5 of

#

T-True

Question [2 F-'False

pts eal

The content of variable FileUnit could be changed by the CALL to the subroutine Readlnfo.

The statement CALL Readlnfo(l5, ReadStatus, varl, var3) it is valid.

The variable inl is a local (^) variable.

tiup:l/web99. auburn. edrlwebgg/p99 1 Slcse I 20lsamplex2. htm. v6/

EXAMZ Winter (^2000) PageT of (^7) f.

UseaDolooptoperfonnthefollowing' '',"'l** ' (^) b n*a successtve lurcs of data from an rnput hle iUR!$ that contains a set of data coordinates ( I integer value (Numbet) (^) and one charaetn (Cqmprrtdlion'11^ The variable Comguifficat have two values Terrunate reading using (^) the .tOSfl4T clause feature for detecting end-of-file conditron. O Open a new-file- that contains on each line the vari ables Numbe4 Conputrtion and Resub where Xeyd (^) rs comput€d by using the Conthiffiasforr.rr.ilaif Coarytaion="C" or.PenwildrioarfanmrrJralf Cuttptution-"P" (kisacons:tant)., *

&od,in,drtnnslaorr:@#h ypcmafiitims,,,'^

*' Nurnher!

(Number- h)l

For each lne, use FANCTION catlsto cslculate the cone spor&ngCombinafons or (^) Permutlions(-5 pts (^) if you don't use FTNCTION calls (^) ) and print it out

,/ ,1 (^) I tn ' y'.,^

'Droblv l"\ (^) , (n'-- r l". Xl 4 \Y. | (^) /nt , (^) -/ t / (^) atr1i u''^^

-l' (^) ' L-(lt''),',,.,r , I f"le"o-t^ tc''(,',-^ .,.,^4 t^ ) L.n, r)) ..,^ l Cl,u^,^ L^'^ A , J (^) ]e,,ty C"oovilol;t 2ll'f'^

qfaTwl

)/ t .t,l '. C)pz-5TL.^ t T ^leeu

'

\ (^) t J.t'r'-( (^) .l l -, 'rl)

IJ

'\

{n'g'

t'-

Y'''-''.'

t (^) ()oir+bl'

\ i '.k.l^

,,ll )^ t.l

,Iqula{"-'"r

rl,

K

fl;

((

TI

ir0r

{

7r'

{,

v

_--

/-/

l"

" "Kr:f

!r:[ ti",:,^ '^

"lrhv

, -^ ]-] ul

1( (^) !',!*f ," ,t1",

.:),'j)

r, - f (^

(,f:n'^"i,t,

::' ,;(.^ NJ".^

|

(n'r''.

,) ^ j,J,^ /v',1. I,(

!r'1n,','o','i*'^

n\ ;^

JL'; |^

(-r''-l-of

ii'* '("-f

'+-

l),.\e

L" |^ ''^

. - , ia- \ N*.'Lnn,

t"1cl't;' 'd"-,i^l

A

/, *1. |^ |^ /'-'-t+ W;)"n"^

- {,^ ^r

/ ,t4. \ l7*'"')'o^

t-

\

olrio (^) r .! rllyfv^t

I

. \6- [wr't' V{J I^ r

'e*I i-t

I ifr'7 ',--'

http:I I w eb99. auburn. (^) ed ul w eb9 9 I p99 I 8/c s e I 2 O/sampl ex2. htm

, (^) i3{.1 $:-,.0^ l 1 t (^) ii, i'.^\


.' ,l i. "., (^) "t .' n,, (^) 4 'l ",'. I^ rii .. ii'.{i';'1 r"}, (^) tL,,, ' .,,.t, (^) " r;t_ (^) ,l (^) I. .;l , I,ld (^) '1 r trr r;,, (^) !. il,-ri:f (^) itl,ii-:

I

./ '\t-OI (^) L, I-..Vv'

,t

/^.(\ *{;a,"^t[v]^ '^

!t

l" : f-!

I

a

\

\


t"

l

L

I ,:i"'; i. (^) ,

f

,r

I ,i 'l

,l

,li'l\t

a\ 1

fur-|";ut-

l''b

rrlit+ l-)x:riitti'r i