Upload
adewumiezekiel
View
221
Download
0
Embed Size (px)
Citation preview
8/16/2019 4 Solutions to Assigned Problems
1/58
Chapter 5
Answers to Review Questions
1. a2. c3. a4. b5. d6. b7. c8. b9. d10. a11. c12. a13. c14. b15. d16. c
17. b18. d19. d20. b
Answers to Exercises
1. Assume the following vaiables contain the values shown!numbe"ed # 100 numbe$lue # 200 numbe%een # 300wod"ed # &'agon( wod$lue # &)*+( wod%een # &%ass(,o each of the following $oolean e-essions/ decide whethe the statement is tue/
false/ o illegal.
a. numbe"ed # numbe$lue ,alse b. numbe$lue numbe%een ,alsec. numbe%een numbe"ed ,alsed. numbe$lue # wod$lue llegale. numbe%een # &%een( llegalf. wod"ed # &"ed( ,alseg. wod$lue # &$lue( ,alseh. numbe"ed # numbe%een uei. numbe$lue # 200 ue
. numbe%een # numbe"ed numbe$lue ue
8/16/2019 4 Solutions to Assigned Problems
2/58
2. A cand+ coman+ wants a list of its bestselling items/ including item numbe andname of cand+. $estselling items ae those that sell ove 2/000 ounds e month. nutecods contain fields fo the item numbe thee digits/ the name of the cand+ 20chaactes/ the ice e ound fou digits/ two assumed decimal laces/ and the:uantit+ in ounds sold last month fou digits/ no decimals.
a. ;esign the int chat fo this ogam. b. ;esign the/ hieach+ chat fo this ogam.c. ;esign the flowchat fo this ogam..d. 'ite the seudocode fo this ogam.
a. Print chart:
1 2 3 4 5 6 7 8 9
1
0
1
1
1
2
1
3
1
4
1
5
1
6
1
7
1
8
1
9
2
0
2
1
2
2
2
3
2
4
2
5
2
6
2
7
2
8
2
9
3
0
1 B e s t S e l l i n g C a n d y
2
3 I t e m N o
4 N a m e
5 9 9 9 X X X X X X X X X X X X X X X X X X X X
6 9 9 9 X X X X X X X X X X X X X X X X X X X X
7
8
9
10
11
b. Hierarchy chart:
main
headings
house*eeing main
8/16/2019 4 Solutions to Assigned Problems
3/58
c. Flowchart:
8/16/2019 4 Solutions to Assigned Problems
4/58
d. Pseudocode:
stat efom house*eeing while not eof efom main
8/16/2019 4 Solutions to Assigned Problems
5/58
3. he same cand+ coman+ descibed in oblem 2 wants a list of its highiced/ bestselling items. $estselling items ae those that sell ove 2/000 ounds e month.@ighiced items ae those that sell fo 10 e ound o moe.
a. ;esign the int chat fo this ogam.
b. ;aw the hieach+ chat fo this ogam.
c. ;aw the flowchat fo this ogam.
d. 'ite the seudocode fo this ogam.
a. Print chart:
1 2 3 4 5 6 7 8 9
1
0
1
1
1
2
1
3
1
4
1
5
1
6
1
7
1
8
1
9
2
0
2
1
2
2
2
3
2
4
2
5
2
6
2
7
2
8
2
9
3
0
1 H i g h P i ! e d B e s t S e l l i n g C a n d y
2
3 I t e m N o N a m e
4
5 9 9 9 X X X X X X X X X X X X X X X X X X X X
6 9 9 9 X X X X X X X X X X X X X X X X X X X X
7
8
910
11
b. Hierarchy chart:
main
headings
house*eeing main
8/16/2019 4 Solutions to Assigned Problems
6/58
c. Flowchart:
8/16/2019 4 Solutions to Assigned Problems
7/58
d. Pseudocode:
stat
efom house*eeing while not eof efom main
8/16/2019 4 Solutions to Assigned Problems
8/58
4. he
8/16/2019 4 Solutions to Assigned Problems
9/58
c. Flowchart:
8/16/2019 4 Solutions to Assigned Problems
10/58
d. Pseudocode:
stat efom house*eeing while not eof efom main
8/16/2019 4 Solutions to Assigned Problems
11/58
5. A telehone coman+ chages 10 cents e minute fo all calls outside the customeDsaea code that last ove 20 minutes. All othe calls ae 13 cents e minute. he honecoman+ has a file with one ecod fo eve+ call made in one da+. n othe wods/ asingle custome might have man+ such ecods on file. ,ields fo each call includecustome aea code thee digits/ custome hone numbe seven digits/ called aeacode thee digits/ called numbe seven digits/ and call time in minutes foudigits. he coman+ wants a eot listing one detail line fo each call/ including thecustome aea code and numbe/ the called aea code and numbe/ the minutes/ and
the total chage.a. ;esign the int chat fo this ogam.
b. ;aw the hieach+ chat fo this ogam.
c. Geate a decision table to use while lanning the logic fothis ogam.
d. ;aw the flowchat fo this ogam.
e. 'ite the seudocode fo this ogam.
a. Print chart:
1 2 3 4 5 6 7 8 9
1
0
1
1
1
2
1
3
1
4
1
5
1
6
1
7
1
8
1
9
2
0
2
1
2
2
2
3
2
4
2
5
2
6
2
7
2
8
2
9
3
0
3
1
3
2
3
3
3
4
3
5
3
6
3
7
3
8
3
9
4
0
4
1
4
2
4
3
4
4
1 P h o n e C a l l s
2
3 ( e a N . / e o ( e a o N . m/ e $i n . t e s C h a g e
4
5 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 + 9 9
6 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 + 9 9
7
8
9
10
11
b. Hierarchy chart:
main
headings
house*eeing main
8/16/2019 4 Solutions to Assigned Problems
12/58
c. ecision !able:
Gondition Hutcome
honeAea # honeoAea , ,
honeEinutes 20 , ,
chage # high"ate I honeEinutes J J J
chage # low"ate I honeEinutes J
8/16/2019 4 Solutions to Assigned Problems
13/58
d. Flowchart:
8/16/2019 4 Solutions to Assigned Problems
14/58
e. Pseudocode:
stat efom house*eeing while not eof
efom main
8/16/2019 4 Solutions to Assigned Problems
15/58
6. A nuse+ maintains a file of all lants in stoc*. Cach ecod contains the name of a lant/ its ice/ and fields that indicate the lantDs light and soil e:uiements. helight field contains eithe &sunn+(/ &atial sun(/ o &shad+(. he soil field containseithe &cla+( o &sand+(. Hnl+ 20 ecent of the nuse+ stoc* does well in shade/ and50 ecent does well in sand+ soil. Gustomes have e:uested a eot that lists thename and ice of each lant that would be aoiate in a shad+/ sand+ +ad.
a. ;esign the int chat fo this ogam.
b. ;aw the hieach+ chat fo this ogam.
c. Geate a decision table to use while lanning the logic fothis ogam.
d. ;aw the flowchat fo this ogam.
e. 'ite the seudocode fo this ogam.
a. Print chart:
1 2 3 4 5 6 7 8 9
1
0
1
1
1
2
1
3
1
4
1
5
1
6
1
7
1
8
1
9
2
0
2
1
2
2
2
3
2
4
2
5
2
6
2
7
2
8
2
9
3
0
3
1
3
2
3
3
3
4
3
5
3
6
3
7
3
8
3
9
4
0
1 P l a n t s o S h a d y S a n d y a d s
2
3 P l a n t N a e P l a n t P i ! e
4
5 X X X X X X X X X X X X X X X X X 9 9 9 9 + 9 9
6 X X X X X X X X X X X X X X X X X 9 9 9 9 + 9 9
7 X X X X X X X X X X X X X X X X X 9 9 9 9 + 9 9
8
9
10
11
b. Hierarchy chart:
main
headings
house*eeing main
8/16/2019 4 Solutions to Assigned Problems
16/58
c. ecision table:
Gondition Hutcome
lant
8/16/2019 4 Solutions to Assigned Problems
17/58
d. Flowchart:
8/16/2019 4 Solutions to Assigned Problems
18/58
e. Pseudocode:
stat efom house*eeing while not eof
efom main
8/16/2019 4 Solutions to Assigned Problems
19/58
7. Lou have declaed vaiables fo an insuance coman+ ogam as follows!
,C
8/16/2019 4 Solutions to Assigned Problems
20/58
b.
if custAge #21 then int custBolic+?umbe/ cust
8/16/2019 4 Solutions to Assigned Problems
21/58
d.
if cust;ueEonth # 2 then int custBolic+?umbe/ cust
8/16/2019 4 Solutions to Assigned Problems
22/58
e.if cust;ueLea 2005 then
int custBolic+?umbe/ cust
8/16/2019 4 Solutions to Assigned Problems
23/58
f.if cust;ueLea 2008 then
int custBolic+?umbe/ cust
8/16/2019 4 Solutions to Assigned Problems
24/58
g.
if cust;ueLea 2004 then int custBolic+?umbe/ cust
8/16/2019 4 Solutions to Assigned Problems
25/58
h.
if custAccidents 11 then int custBolic+?umbe/ cust
8/16/2019 4 Solutions to Assigned Problems
26/58
.
if custAccidents # 0 then int custBolic+?umbe/ cust
8/16/2019 4 Solutions to Assigned Problems
27/58
8. )tudent files contain an ; numbe fou digits/ last and fist names 15 chaacteseach/ and mao field of stud+ 10 chaactes. Blan a ogam that lists ; numbesand names fo all ,ench o )anish maos.
a. ;esign the int chat fo this ogam.
b. ;aw the hieach+ chat fo this ogam.
c. Geate a decision table to use while lanning the logic fothis ogam.
d. ;aw the flowchat fo this ogam.
e. 'ite the seudocode fo this ogam.
a. Print chart:
1 2 3 4 5 6 7 8 9
1
0
1
1
1
2
1
3
1
4
1
5
1
6
1
7
1
8
1
9
2
0
2
1
2
2
2
3
2
4
2
5
2
6
2
7
2
8
2
9
3
0
3
1
3
2
3
3
3
4
3
5
3
6
3
7
3
8
3
9
4
0
4
1
4
2
4
3
4
4
1 - e n ! h a n d S a n i s h $a % o s
2
3 I N . m/ e , a s t N a me - i s t N a me
45 9 9 9 9 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X
6 9 9 9 9 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X
7 9 9 9 9 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X
8
9
10
11
b. Hierarchy chart:
c. ecision table:
Gondition Hutcome
stuEa o # &,ench( , ,
stuEao # &)anish( , ,
int J J J
donDt int J
main
headings
house*eeing main
8/16/2019 4 Solutions to Assigned Problems
28/58
d. Flowchart:
8/16/2019 4 Solutions to Assigned Problems
29/58
8/16/2019 4 Solutions to Assigned Problems
30/58
9. A floist wants to send couons to he best customes/ so she needs a list of namesand addesses fo customes who laced odes moe than thee times last +ea osent moe than 200 last +ea. he inut file descition follows!
File na"e: F#$R%&!C'&!&,C
8/16/2019 4 Solutions to Assigned Problems
31/58
8/16/2019 4 Solutions to Assigned Problems
32/58
c. ecision table:
Gondition Hutcome
floHdes ode
8/16/2019 4 Solutions to Assigned Problems
33/58
8/16/2019 4 Solutions to Assigned Problems
34/58
10. A caente needs a ogam that comutes the ice of an+ des* a custome odes based on the following inut fields! ode numbe/ des* length and width theedigits each/ no decimals/ t+e of wood 20 chaactes/ and numbe of dawes twodigits. he ice is comuted as follows!
• he chage fo all des*s is a minimum 200.
• f the suface length I width is ove 750 s:uaeinches/ add 50.
• f the wood is &mahogan+( add 150O fo &oa*( add125. ?o chage is added fo &ine.(
• ,o eve+ dawe in the des*/ thee is an additional30 chage.
a. ;esign the int chat fo this ogam.
b. ;aw the hieach+ chat fo this ogam.
c. Geate a decision table to use while lanning the logic fothis ogam.
d. ;aw the flowchat fo this ogam.
e. 'ite the seudocode fo this ogam.
a. Print chart:
1 2 3 4 5 6 7 8 9
1
0
1
1
1
2
1
3
1
4
1
5
1
6
1
7
1
8
1
9
2
0
1 e s P i ! e s
2
3 N . / e P i ! e
4
5 9 9 9 9 9 9 + 9 9
6 9 9 9 9 9 9 + 9 9
7 9 9 9 9 9 9 + 9 9
8
9
10
11
b. Hierarchy chart:
main
headings
house*eeing main
8/16/2019 4 Solutions to Assigned Problems
35/58
c. ecision table:
Condition $utco"e
suface 750 , , , ,
wood #FEahogan+F
, , , ,
wood # FHa*F , , , ,
ice$efoe;awes# 200 J
ice$efoe;awes# 250
J
ice$efoe;awes# 325
J
ice$efoe;awes# 350
Jimossible J
ice$efoe;awes# 375
J
ice$efoe;awes
# 400
J
imossible
J
8/16/2019 4 Solutions to Assigned Problems
36/58
d. Flowchart:
8/16/2019 4 Solutions to Assigned Problems
37/58
e. Pseudocode:
stat efom house*eeing while not eof
efom main
8/16/2019 4 Solutions to Assigned Problems
38/58
8/16/2019 4 Solutions to Assigned Problems
39/58
c. ecision table:
Gondition Hutcome
emGit+ #('oodstoc*( , ,
emGit+ #('onde
8/16/2019 4 Solutions to Assigned Problems
40/58
e. Pseudocode:
stat efom house*eeing while not eof
efom main
8/16/2019 4 Solutions to Assigned Problems
41/58
12. A sueviso in a manufactuing coman+ wants to oduce a eot showing whichemlo+ees have inceased thei oduction this +ea ove last +ea/ so that she canissue them a cetificate of commendation. )he wants to have a eot with theecolumns! last name/ fist name/ and eithe the wod &=B( o blan*s inted unde thecolumn heading B"H;=GH?. &=B( is inted when this +eaDs oduction is ageate numbe than last +eaDs oduction. nut e-ists as follows!
B"H;=GH? ,
8/16/2019 4 Solutions to Assigned Problems
42/58
c. ecision table:
d. Flowchart:
Gondition Hutcome
thisLeasBoduction lastLeasBoduction
,
int J
donDt int J
8/16/2019 4 Solutions to Assigned Problems
43/58
e. Pseudocode:
stat efom house*eeing while not eof
efom main
8/16/2019 4 Solutions to Assigned Problems
44/58
13. A sueviso in the same manufactuing coman+ as descibed in C-ecise 12 wantsto oduce a eot fom the B"H;=GH? inut file showing bonuses she is lanning to give based on this +eaDs oduction. )he wants to have a eot withthee columns! last name/ fist name/ and bonus. he bonuses will be distibuted asfollows.
f this +eaDs oduction is!
• 1/000 units o fewe/ the bonus is 25
• 1/001 to 3/000 units/ the bonus is 50
• 3/001 to 6/000 units/ the bonus is 100
• 6/001 units and u/ the bonus is 200
a. ;esign the int chat fo this ogam.
b. ;aw the hieach+ chat fo this ogam.
c. Geate a decision table to use while lanning the logic fothis ogam.
d. ;aw the flowchat fo this ogam.
e. 'ite the seudocode fo this ogam.
a. Print chart:
1 2 3 4 5 6 7 8 9
1
0
1
1
1
2
1
3
1
4
1
5
1
6
1
7
1
8
1
9
2
0
2
1
2
2
2
3
2
4
2
5
2
6
2
7
2
8
2
9
3
0
3
1
3
2
3
3
3
4
3
5
3
6
3
7
3
8
3
9
4
0
4
1
4
2
4
3
4
4
4
5
4
6
4
7
4
8
4
9
1 # m l o y e e P o d . ! t i o n e o t
2
3 , a s t N a me - i s t N a me B o n . s
4
5 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X 9 9 9
6 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X 9 9 9
7
89
10
11
b. Hierarchy chart:
main
headings
house*eeing main
8/16/2019 4 Solutions to Assigned Problems
45/58
c. ecision table:
Gondition Hutcome
emhisLea # 1000 , , , , , , , ,
emhisLea # 3000 , , , , , , , ,
emhisLea # 6000 , , , , , , , ,
emhisLea 6000 , , , , , , , , bonus # 200 J
bonus # 100 J
bonus # 50 J
bonus # 25 J
8/16/2019 4 Solutions to Assigned Problems
46/58
d. Flowchart:
8/16/2019 4 Solutions to Assigned Problems
47/58
8/16/2019 4 Solutions to Assigned Problems
48/58
e. Pseudocode:
stat efom house*eeing while not eof
efom main
8/16/2019 4 Solutions to Assigned Problems
49/58
14. Eodif+ C-ecise 13 to eflect the following new facts/ and have the ogame-ecute as efficientl+ as ossible!
o Hnl+ emlo+ees whose oduction this +ea ishighe than last +ea will eceive bonuses. his is tue fo ao-imatel+ 30Qof the emlo+ees.
o )i-t+ ecent of emlo+ees oduce ove 6/000units e +ea/ 20Q oduce 3/001 to 6/000/ 15Q oduce 1/001 to 3/000 units/and onl+ 5Q oduce fewe than 1/001.
a. ;esign the int chat fo this ogam.
b. ;aw the hieach+ chat fo this ogam.
c. Geate a decision table to use while lanning the logic fothis ogam.
d. ;aw the flowchat fo this ogam.
e. 'ite the seudocode fo this ogam.
a. Print chart:
1 2 3 4 5 6 7 8 9
1
0
1
1
1
2
1
3
1
4
1
5
1
6
1
7
1
8
1
9
2
0
2
1
2
2
2
3
2
4
2
5
2
6
2
7
2
8
2
9
3
0
3
1
3
2
3
3
3
4
3
5
3
6
3
7
3
8
3
9
4
0
4
1
4
2
4
3
4
4
4
5
4
6
4
7
4
8
4
9
1 # m l o y e e P o d . ! t i o n e o t
2
3 , a s t N a me - i s t N a me B o n . s
4
5 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X 9 9 9
6 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X 9 9 9
7
8
910
11
b. Hierarchy chart:
main
headings
house*eeing main
8/16/2019 4 Solutions to Assigned Problems
50/58
c. ecision table:
Gondition Hutcome
emhisLea em
8/16/2019 4 Solutions to Assigned Problems
51/58
d. Flow chart
8/16/2019 4 Solutions to Assigned Problems
52/58
8/16/2019 4 Solutions to Assigned Problems
53/58
e. Pseudocode:
stat efom house*eeing while not eof
efom main
8/16/2019 4 Solutions to Assigned Problems
54/58
15. he "ichmond "iding Glub wants to assign the title of Easte o ?ovice to each ofits membes. A membe eans the title of Easte b+ accomlishing two o moe ofthe following!
Baticiating in at least eight hose shows
'inning a fist o second lace ibbon in at leasttwo hose shows/ no matte how man+ shows the membe has aticiated in
'inning a fist/ second/ thid o fouth lace ibbonin at least fou hose shows/ no matte how man+ shows the membe has aticiated in
Geate a eot that ints each club membeKs name along with the designationFEasteF o F?oviceF. nut e-ists as follows!
B"H;=GH? ,
8/16/2019 4 Solutions to Assigned Problems
55/58
b. Hierarchy chart:
c. ecision !able:
Gondition Hutcome
iding)hows # 8 , , , ,fistH)econd # 2 , , , ,
fisthough,outh# 4
, , , ,
title # FEasteF J J J J
title # K?oviceF J J J J
main
headings
house*eeing main
8/16/2019 4 Solutions to Assigned Problems
56/58
d. Flow Chart
8/16/2019 4 Solutions to Assigned Problems
57/58
8/16/2019 4 Solutions to Assigned Problems
58/58
e. Pseudocode:
stat efom house*eeing while not eof efom main