CPSC 13 75
P rogram m ing I
HW4
(A cl a ssi ca l “s i ng le c o ntr ol bre ak” pro ble m )
T he re s u l ts of a ser ie s of quizzes i n a certain cours e ar e i n t he da t a f il e ” q u i zze s . dat”. A ty pi cal re c ord in t his file c ons i sts of a s tudent’s I D num ber ( of type int) and a qu i z score ( also of type i nt ) f or the stud e n t . T he fi l e is arrang e d so that a ll t he records for a part i cular stud en t are l u m ped together; t o ill u s trate, the f i rst fe w r ecords i n t he fi l e are:
67 1 00 53
qui z sc ores f or stu d ent # 10234
in no
q u i z scores for student # 11 245
99
1 023 4 1 023 4 1 02 34 10 234 1 124 5 1 124 5 1 1245 14 6 5 2 1 4652 1 465 2 1 465 2 1 465 2 1465 2 1983 2
1 00 56 99 1 00 9 6
q uiz scores for student # 14 6 52 Not e t hat t h e n u m b e r of q u izzes a stu de n t has tak e n can v ar y!
Y our jo b is to wr i te a C++ program t o loop thr ou gh this f i le and, fo r each stu de nt, output the stu de n t’ s I D number a lo ng wi th t h e student ‘ s qui z av e ra g e a f t er th e highes t an d lo w es t q uiz scores fo r the s tudent has been thrown out. T hus, i n o ur examp l e, the f irst f e w li n e s of yo u r output s hou l d l ook li k e
1 023 4 1 1 24 5 14 6 52
79 . 00 89 . 00 93 . Program ming notes:
( 1 ) . I n outputt i ng, format the aver a ges to two d e cima l- p l ac e accuracies . A l so k e ep in m i nd that “i nteger div i s i on truncat e s”, i. e. , rem em ber to use “ca s ts”. (2) . Y ou can assume that eve r yone i n t h e f il e has taken at least three qu i zzes, i . e ., you n ee d not worry about “d ivi din g by ze r o”
(c on ti nu ed o n ba ck) page 2
after the maximum and mi n i m um grades ha v e been thrown out.
(3) . Note that you sho ul d throw out on ly o ne occurrence of the maxi mu m and not a l l occurr e n c es. ( S e e studen t # 1 4 65 2 abo v e.) A si m i lar statem e nt a pp lie s to m i n i mu m g rad e s. (4). A programming h i n t : Make a “spec i al case” out of the f i rst record in the fi le by r e ad i ng it i n separat el y, and then, in y our ma i n l oop, r e a d r ec ords and react accord i n gly d epend i n g o n whe t h e r th e I D f i e ld i s di ff e rent or the same a s the pre v i ou s I D in putted.








Jermaine Byrant
Nicole Johnson



