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

1. 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 #. Answer: name[3] %.rob %*-ith the selection sort. Search the arra( in .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. Oo. co"t EE test1 EE F F EEtest2 EE en lC Answer: 71 90 90 100 2. . After 2 iterations -hat -ill the arra( loo? li?eH 2 .roblem 2 above in part 'c* for KtL an tell -here it is locate .o (o" initiali=e an integer arra( of si=e + to the val"es sho-n belo-H 0he arra( is calle bigarra(. Sort the arra( above '. 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 +.

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.Answer: -1. 1rite a eclaration for a t-o imensional arra( to hol # integer e5am scores for each of 20 st" ents.e( are *ass--(-reference *arameters.art b eals -ith the calling obPect. 5 6. 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.e t. . 10.e 0al e of its calling o-1ect Answer: /. 2.e( cannot -e mo#ifie# -( t.e . cannot -e c.ange# in t. t. Answer: if looking for 25 will ret rn !1 "item not fo n#$ if looking for 7 will ret rn in#e% & 3 /.ir# n m-er -etween 0 an# m 2. 6. Answer: int e%am'ar([20][3]) 8. t. # . 7.ic.e #eclaration is *lace# -efore main.one( f ntion b* Do"ble getAval"e'* constC Answer: /.o g.ir# se of const is to create a name# constant w.e *rogram+ 2f t.e mem-er f nction get'0al e cannot mo#if( t. 1hat is const "se for in the t-o protot(pesH Gotice the first is passe b( reference an has a constant. 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 /.

'+* EE ( 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#.(C co"t EE set-'+* EE 5 EE set.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 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 = .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.

:) < co t 66 en#l) < 1+.is is not a cstring or a string$ + .ar# >ose*.en gar-age since t.ar#"t. =ic. i =ic. =ic. 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 :. 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.1%.ar# >ose*.>ose*.ar# >ose*.

Sn icate the or er of comp"tation for this e5pression: A ! Y 8 C ! 'D 6 'Q 7 &** R 8* R . .=ic. atM*C Answer: w.iven the follo-ing) ho.01 thing ifstream infileC o"ble partAn"mC string partA esC infile.open'Fa:parts.ile "Binfile+eof"$$9 @@ #o st ff infile?? *art'n m ??*art'#es) < A= 12. 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 ++.0+ -hat(amacallit 1+6. } 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.01 gi=mo 112.ile "infile ?? *art'n m ?? *art'#es$9 @@#o st ff < infile ?? *art'n m ?? *art'#es) w. 5 4 6 2 1 3 7 1/. 16.-o"l (o" rea a file containing part n"mbers an part escriptions that loo?e li?e this: 112. 1hat -ill be assigne to res"lt after the follo-ing s-itch statement is e5ec"te H 6 . 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. 1hat is s"m after the e5ec"tion of this co e: int P) k.

eclare obPects of that class t(pe b. .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. 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 / . Ye able to "se the class in an application to a.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*.ing 6 22.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. call the constr"ctors c. .

E5arl(F.ive Qarl Qarl( a +6 raise. 3alarie#5m*lo(ee 5arl"E5arlF. 5m*1+*rint'em*"co t$) 8 .o l# -e a-le to write all of t. 5arl+c. 3alarie#5m*lo(ee 5m*1) Declare a ne. 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.rint the emplo(ee information for the first emplo(ee (o" entere . 5arl+gi0e'raise"+05$) . 123323333$) Change QarlLs marriage stat"s to $.ange'salar("7000$) .emplo(ee "sing the efa"lt constr"ctor.emplo(ee calling the secon constr"ctor -ith the name Qarl Qarl( an ssn of 12##2####.the emplo(eeLs salar(. 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. 1rite the class efinition an class f"nctions.e a-o0e f nctions+ Declare a ne.ive Qarl a salar( of Z%)000 5arl+c.ange'marr('stat"GmH$) .