You are on page 1of 8

ACS 168 Final exam Review Material Covered: Savitch chapters 1-10 Labs: All of them Topics 1. 2. #. %. +. 6. /. 8. 2. 10.

11. 12. 1#. 1%. 1+. 16. 1/. 18. 12. 20. 21. 22. 2#. 2%. 2+. 26. Design: class charts Co ing in C!! an eb"gging in C!! $ath in C!! &"nctions 'protot(pes) calls) hea ers* ,assing b( val"e an passing b( reference a* ,rotot(pes nee to match f"nctions hea ers b* Call parameters can be ifferent an onl( follo- the or er not the name .eneral format of C!! program 0race co e 1rite co e 3ariable names Constants An ) or logic 4no- the or er of operations '5 ! (6#7+8% ! +7'5 ! (6%** Statements 'assignment) call) if) s-itch) for loop) o"ble for loop) -hile loop) inp"t) o"tp"t) braces9:) s(nta5* Data t(pes 'int) char) o"ble*) Class ;"tp"t formatting Character inp"t an o"tp"t Character f"nctions S-itch ----<emember the Break Arra(s: eclare) initiali=e) inp"t) o"tp"t Searching an Sorting>?no- the ifference 3ali ation Logic Strings>4no- ho- to a strings together 'concatenate* 0e5t file processing -ith integer an character ata Classes an class f"nctions &rien f"nctions @se of const

1.

.iven the f"nction efinition: o"ble calcAavg 'intB test1) int test2* 9 o"ble avgC avg D 'test1 ! test2 * 8 ' o"ble*2 C co"t EE test1 EE F F EEtest2 EE en lC test1 D 100C test2 D 2+C ret"rn avgC : 1hat val"e is assigne to avg if : int test1 D 20) test2 D /1C o"ble avgC calcAavg ' test2) test1 *C. co"t EE test1 EE F F EEtest2 EE en lC Answer: 71 90 90 100

2.

1hat is the correct eclaration an initiali=ation for the cstring LastGameH a* char name IJ D 9K&L) K"L) KlL) KtL) KoL) KnL:C b* char name I6JD F&"ltonMC c* char name I/JD F&"ltonMC * char name I6J D 9K&L) K"L) KlL) KtL) KoL) KnL) KN0L:C e* none of the above Answer: c

#.

Search the arra( in ,roblem 2 above in part 'c* for KtL an tell -here it is locate . Answer: name[3]

%.

Oo- o (o" initiali=e an integer arra( of si=e + to the val"es sho-n belo-H 0he arra( is calle bigarra(. 6 2 -1 / + a* b* c* * int bigarra(I+JD90:C int bigarra(I+JD96)2)-1)+)/:C int bigarra(I+JD96)2)-1)/)+:C none of the above

Answer: c +. Sort the arra( above ',rob %*-ith the selection sort. After 2 iterations -hat -ill the arra( loo? li?eH

Answer: -1, 2, 6, 7, 5 6. 1hat -ill be ret"rne from "sing the Linear search algorithm on the arra( in problem % if -e are loo?ing for 2+C -hat abo"t loo?ing for /. Answer: if looking for 25 will ret rn !1 "item not fo n#$ if looking for 7 will ret rn in#e% & 3 /. 1rite a eclaration for a t-o imensional arra( to hol # integer e5am scores for each of 20 st" ents. Answer: int e%am'ar([20][3]) 8. 1hat is const "se for in the t-o protot(pesH Gotice the first is passe b( reference an has a constant. ,art b eals -ith the calling obPect. 1hat is the other "se for constH a* &rien $one( a 'const $one( B amo"nt1) const $one(B amo"nt2*C Answer: const makes amo nt1 an# amo nt2 constant *arameters+ Alt,o g, t,e( are *ass--(-reference *arameters, t,e( cannot -e mo#ifie# -( t,e .one( f ntion b* Do"ble getAval"e'* constC Answer: /,e mem-er f nction get'0al e cannot mo#if( t,e 0al e of its calling o-1ect Answer: /,e t,ir# se of const is to create a name# constant w,ic, cannot -e c,ange# in t,e *rogram+ 2f t,e #eclaration is *lace# -efore main, it is calle# a glo-al name# constant+ e%+ const int 3245 & 15) 1hat is the ifference bet-een a frien f"nction an a member f"nctionH see te%t 1hat oes the follo-ing f"nction oH total D 0C for 'i D 0C i ED mC iDi!#* totalD total ! i Answer: a## e0er( t,ir# n m-er -etween 0 an# m

2. 10.

11.

voi m(ster('int arr1IJ) int arr2IJ) int n"mQlems* 9 int P) ?Dn"mQlems R1C for 'PD0: P E n"mQlemsC P!!* 9 arr1IPJ D arr2I?JC ?--C : : Answer: /,is writes t,e elements in arr2 into arr1 in re0erse or#er 1hat is the o"tp"t belo-H voi tall('int 5) int () int B =*C voi s"m 'int =*C voi main '* 9 int 5 D 1) (D 2) =D #C tall( '5)()=*C co"t EE set-'+* EE 5 EE set- '+* EE ( EE set- '+* EE = EE en lC s"m '=*C co"t EE =C : voi tall('int 5) int () int B =* 9 = D 5 ! 2(C 5 D 5!=C ( D = - (C co"t EE set-'+* EE 5 EE set- '+* EE ( EE set- '+* EE = EE en lC : voi s"m 'int =* 9 = D = ! =C : Answer: 6 3 5 1 2 5 5 Snitiali=e an arra( li?e: int bigarra( I2JI#JD 91)2)#)%)+)6:C 1hat is store at bigarra( I1JI2JH Answer: 6

12.

1#.

1%. 1rite neste for loops to print the follo-ing pattern: 7 77 777 7777 Answer: for "int 1 & 1) 1 6& 7) 188$ 9 for "int k & 1) k 6& 1) k88$ 9 co t 66 :;:) < co t 66 en#l) < 1+. 1hat is printe o"t belo-H Tincl" e EiostreamU Tincl" e EcstringU Tincl" e EstringU "sing namespace st C int main '* 9 string <ich D V<ichar V)Woe D VWosephV )s"mnameC char nameIJ D 9X<X) XiX)XcX) XhX) XaX) XrX) X X:C char name2IJ D 9X<X) XiX)XcX) XhX)XN0X:C co"t EE <ich EE V V EE Woe EE en lEE en lC s"mname D <ich ! V V ! WoeC co"t EE s"mname EE en lEEen lEE en lC s"rname !D WoeC co"t EE s"mname EE en lEEen lEE en lC co"t EE name I1JEE en lEE en l EE name EE en lEE en lC co"t EE name2 EE en lC ret"rn 0C :
Answer: =ic,ar# >ose*, =ic,ar# >ose*, =ic,ar# >ose*,>ose*, i =ic,ar#"t,en gar-age since t,is is not a cstring or a string$

=ic,

16. Sn icate the or er of comp"tation for this e5pression: A ! Y 8 C ! 'D 6 'Q 7 &** R 8* R . 5 4 6 2 1 3 7 1/. 1hat is s"m after the e5ec"tion of this co e: int P) k, s"m D 0C int ar(I#JI%JC for'P D 0C PE#C P!!* for '?D0C ? E %C ?!!*{ ar(IPJI?J D s"m ! 1C sum ++; } s"m D 0C for 'P D 0C P E %C P!!* s"m !D ar(I2JIPJC 88-hat oes this co e oH Answer: fills arra( in or#er wit, 1-12 'ScottLs class note highlighte changes in co e* 88-hat oes this co e oH Answer: totals 0al es in row 2 of arra(

18. .iven the follo-ing) ho- -o"l (o" rea a file containing part n"mbers an part escriptions that loo?e li?e this: 112.01 gi=mo 112.0+ -hat(amacallit 1+6.01 thing ifstream infileC o"ble partAn"mC string partA esC infile.open'Fa:parts. atM*C Answer: w,ile "infile ?? *art'n m ?? *art'#es$9 @@#o st ff < infile ?? *art'n m ?? *art'#es) w,ile "Binfile+eof"$$9 @@ #o st ff infile?? *art'n m ??*art'#es) <

A=

12. 1hat -ill be assigne to res"lt after the follo-ing s-itch statement is e5ec"te H

choice D KaLC s-itch 'choice* 9 case KaL: res"lt D 100C case KbL: res"lt D 200C case KcL: res"lt D #00C efa"lt: res"lt D 0C : Answer: res lt & 0 20. 1hen -e split o"r file for separate compilation) -hich files ma?e "p the AD0 interface) implementation) an application filesH Answer: see te%t 21. .iven the follo-ing if 'a == b* if 'c E a* 9 if 'b U c* co"t EE bC else co"t EE cC : else co"t EE aC 1hat is printe if a D #) b D %) c D +H 1hat if a D 6) b D 6) c D 12H 1hat if a D 6) b D 6) c D +H Answer: Answer: Answer: 3 not,ing 6

22. .iven a escription of a class an it member f"nctions) be able to -rite a class efinition an the f"nction efinitions for all f"nctions 'incl" ing constr"ctors) accessor f"nctions) an other f"nctions*. Ye able to "se the class in an application to a. eclare obPects of that class t(pe b. call the constr"ctors c. assign val"es to the ata members &or practice: Define a class Salarie Qmplo(ee that ?eeps trac? of the emplo(eeLs name) ssn) monthl( salar() an marital stat"s. 0he class sho"l provi e p"blic metho s to print a pa(chec?) print emplo(ee information) give the emplo(ee a percentage raise) change the emplo(eeLs marital stat"s) an change

the emplo(eeLs salar(. 0he efa"lt constr"ctor sho"l set as? the "ser for the emplo(ee informationC a secon constr"ctor sho"l accept a name an ssn. 1rite the class efinition an class f"nctions. Class #efinition: class Salarie Qmplo(ee 9 p"blic: Salarie Qmplo(ee'*C Salarie Qmplo(ee'string fname) string lname) string soc*C voi printApa('ostreamB o"tfile*C voi printAemp'ostreamB o"tfile*C voi giveAraise' o"ble percentAraise*C voi changeAmarr(Astat'char ne-Astat*C voi changeAsalar(' o"ble ne-Asalar(*C private: string firstAnameC string lastAnameC string ssnC o"ble monthl(Asalar(C char maritalAstat"sC : Do s,o l# -e a-le to write all of t,e a-o0e f nctions+ Declare a ne- emplo(ee "sing the efa"lt constr"ctor. 3alarie#5m*lo(ee 5m*1) Declare a ne- emplo(ee calling the secon constr"ctor -ith the name Qarl Qarl( an ssn of 12##2####. 3alarie#5m*lo(ee 5arl"E5arlF, E5arl(F, 123323333$) Change QarlLs marriage stat"s to $. 5arl+c,ange'marr('stat"GmH$) .ive Qarl a salar( of Z%)000 5arl+c,ange'salar("7000$) .ive Qarl Qarl( a +6 raise. 5arl+gi0e'raise"+05$) ,rint the emplo(ee information for the first emplo(ee (o" entere . 5m*1+*rint'em*"co t$)

You might also like