Вы находитесь на странице: 1из 58

Chapter 5

Answers to Review Questions


1. a
2. c
3. a
4. b
5. d
6. b
7. c
8. b
9. d
10. a
11. c
12. a
13. c
14. b
15. d
16. c
17. b
18. d
19. d
20. b
Answers to Exercises
1. Assume the following variables contain the values shown:
numberRed = 100
numberBlue = 200 numberGreen = 300
wordRed = Wagon
wordBlue = Sky wordGreen = Grass
For each of the following Boolean expressions, decide whether the statement is true,
false, or illegal.
a.
b.
c.
d.
e.
f.
g.
h.
i.
j.

numberRed = numberBlue?
numberBlue > numberGreen?
numberGreen < numberRed?
numberBlue = wordBlue?
numberGreen = Green?
wordRed = Red?
wordBlue = Blue?
numberRed <= numberGreen?
numberBlue >= 200?
numberGreen >= numberRed + numberBlue?

False
False
False
Illegal
Illegal
False
False
True
True
True

2. A candy company wants a list of its best-selling items, including item number and
name of candy. Best-selling items are those that sell over 2,000 pounds per month. Input
records contain fields for the item number (three digits), the name of the candy (20
characters), the price per pound (four digits, two assumed decimal places), and the
quantity in pounds sold last month (four digits, no decimals).
a. Design the print chart for this program.
b. Design the, hierarchy chart for this program.
c. Design the flowchart for this program..
d. Write the pseudocode for this program.

a. Print chart:
1 1 1
1 2 3 4 5 6 7 8 9 0 1 2
1
Be s t
S
2
3 I t e m No
4
5
9 9 9
X X
6
9 9 9
X X
7
8
9
10
11

1 1 1 1 1 1 1 2 2
3 4 5 6 7 8 9 0 1

2 2 2 2 2 2 2 2 3
2 3 4 5 6 7 8 9 0

e l l i

n d y

n g

Ca

N a m e
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 X X X X X X

b. Hierarchy chart:

main( )

housekeeping( )

headings( )

mainLoop( )

finishUp( )

c.

Flowchart:

d. Pseudocode:
start
perform housekeeping( )
while not eof
perform mainLoop( )
endwhile
perform finishUp( )
stop
housekeeping( )
define variables
open files
perform headings( )
read candyRec
return
headings( )
print heading1
print heading2
return
mainLoop( )
if candyQuantity > 2000 then
print candyNum, candyName,
endif
read candyRec
return
finishUp( )
close files
return

3. The same candy company described in problem 2 wants a list of its high-priced, bestselling items. Best-selling items are those that sell over 2,000 pounds per month.
High-priced items are those that sell for $10 per pound or more.
a.
Design the print chart for this program.
b.
Draw the hierarchy chart for this program.
c.
Draw the flowchart for this program.
d.
Write the pseudocode for this program.
a. Print chart:
1
1H i
2
3I t
4
5
6
7
8
9
10
11

1 1 1 1 1 1 1 1 1 1 2 2 2
4 5 6 7 8 90 1 2 3 4 5 6 7 8 9 0 1 2
h
P r i c e d
B e s t
S e l l i

9
9

N o

2 2 2 2 2 2 2 3
3 4 5 6 7 8 9 0
n g
C a n d y

N a m e

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 X X
X X X X X X X X

b. Hierarchy chart:
main( )

housekeeping( )

headings( )

mainLoop( )

finishUp( )

c. Flowchart:

d. Pseudocode:
start
perform housekeeping( )
while not eof
perform mainLoop( )
endwhile
perform finishUp( )
stop
housekeeping( )
define variables
open files
perform headings( )
read candyRec
return
headings( )
print heading1
print heading2
return
mainLoop( )
if candyQuantity > 2000 then
if candyPrice >= 10 then
print candyNum, candyName,
endif
endif
read candyRec
return
finishUp( )
close files
return

4. The Literary Honor Society needs a list of English majors who have a grade point average
of 3.5 or higher. The student record file includes students last names and first names (15
characters each), major (10 characters, for example History or English), and grade
point average (two digits, one assumed decimal place, for example 3.9 or 2.0).
a.
Design the print chart for this program.
b.
Draw the hierarchy chart for this program.
c.
Draw the flowchart for this program.
d.
Write the pseudocode for this program.

a. Print chart:
1 2 3
1 En g
2
3
4
5 XXX
6 XXX
7
8
9
10
11

1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4
4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
l i s h
Ma j o r s
wi t h
GP A >
= 3 . 5
L a s t

N a me

XXXXXXXXXXXX
XXXXXXXXXXXX

F i r s t

N a me

XXXXXXXXXXXXXXX
XXXXXXXXXXXXXXX

b. Hierarchy chart:
main( )

housekeeping( )

headings( )

mainLoop( )

finishUp( )

c. Flowchart:

d. Pseudocode:
start
perform housekeeping( )
while not eof
perform mainLoop( )
endwhile
perform finishUp( )
stop
housekeeping( )
define variables
open files
perform headings( )
read stuRec
return
headings( )
print heading1
print heading2
return
mainLoop( )
if stuMajor = "English" then
if stuGpa >= 3.5 then
print stuLast, stuFirst
endif
endif
read stuRec
return
finishUp( )
close files
return

5. A telephone company charges 10 cents per minute for all calls outside the customers
area code that last over 20 minutes. All other calls are 13 cents per minute. The phone
company has a file with one record for every call made in one day. (In other words, a
single customer might have many such records on file.) Fields for each call include
customer area code (three digits), customer phone number (seven digits), called area
code (three digits), called number (seven digits), and call time in minutes (four
digits). The company wants a report listing one detail line for each call, including the
customer area code and number, the called area code and number, the minutes, and
the total charge.
a.
Design the print chart for this program.
b.
Draw the hierarchy chart for this program.
c.
Create a decision table to use while planning the logic for
this program.
d.
Draw the flowchart for this program.
e.
Write the pseudocode for this program.
a.

Print chart:

1 1 1 1 1 1 1 1 1 1 2 2 2 2 2
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
1
Ph o n e
Ca l
2
3
Ar e a
N u mb e r
T o Ar e a
T o
N
4
5 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
7
8
9
10
11

2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4
5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
l s
u mb e r
9 9 9
9 9 9

Mi n u t e s
9 9 9 9
9 9 9 9

Ch a r g e
9 9 . 9 9
9 9 . 9 9

b. Hierarchy chart:
main( )

housekeeping( )

headings( )

mainLoop( )

finishUp( )

c. Decision Table:
Condition
phoneArea = phoneToArea
phoneMinutes > 20
charge = highRate * phoneMinutes
charge = lowRate * phoneMinutes

Outcome
T
T
T
F
X
X

F
T
X

F
F
X

d. Flowchart:

e. Pseudocode:
start
perform housekeeping( )
while not eof
perform mainLoop( )
endwhile
perform finishUp( )
stop
housekeeping( )
define variables
open files
perform headings( )
read phoneRec
return
headings( )
print heading1
print heading2
return
mainLoop( )
if phoneArea = phoneToArea then
charge = phoneMinutes * highRate
else
if phoneMinutes > 20 then
charge = phoneMinutes * lowRate
else
charge = phoneMinutes * highRate
endif
endif
print phoneArea, phoneNum, phoneToArea, phoneToNum, phoneMinutes, charge
read phoneRec
return
finishUp( )
close files
return

6. A nursery maintains a file of all plants in stock. Each record contains the name of a
plant, its price, and fields that indicate the plants light and soil requirements. The
light field contains either sunny, partial sun, or shady. The soil field contains
either clay or sandy. Only 20 percent of the nursery stock does well in shade, and
50 percent does well in sandy soil. Customers have requested a report that lists the
name and price of each plant that would be appropriate in a shady, sandy yard.
a.
Design the print chart for this program.
b.
Draw the hierarchy chart for this program.
c.
Create a decision table to use while planning the logic for
this program.
d.
Draw the flowchart for this program.
e.
Write the pseudocode for this program.

a. Print chart:
1 2 3 4 5
1
Pl a
2
3 Pl a n t
4
5 XXXXX
6 XXXXX
7 XXXXX
8
9
10
11

1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4
6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
n t s
f o r
Sh a d y ,
Sa n d y
Ya r d s
N a me

Pl a n t

XXXXXXXXXXXX
XXXXXXXXXXXX
XXXXXXXXXXXX

Pr i c e

9 9 9 9 . 9 9
9 9 9 9 . 9 9
9 9 9 9 . 9 9

b. Hierarchy chart:
main( )

housekeeping( )

headings( )

mainLoop( )

finishUp( )

c. Decision table:
Condition
plantLight = "shady"
plantSandy = "sandy"
print plantName
don't print

Outcome
T
T
T
F
X
X

F
T

F
F

d. Flowchart:

e. Pseudocode:
start
perform housekeeping( )
while not eof
perform mainLoop( )
endwhile
perform finishUp( )
stop
housekeeping( )
define variables
open files
perform headings( )
read plantRec
return
headings( )
print heading1
print heading2
return
mainLoop( )
if plantLight = "shady" then
if plantSoil = "sandy" then
print plantName
endif
endif
read plantRec
return
finishUp( )
close files
return

7. You have declared variables for an insurance company program as follows:


FIELD
POSITIONS
EXAMPLE
num custPolicyNumber
16
223356
char custLastName
720
Falkenburg
num custAge
2123
25
num custDueMonth
2425
06
num custDueDay
2627
24
num custDueYear
2831
2005
num custAccidents
3234
2
Draw the flowchart or write the pseudocode for the selection structures that print the
custPolicyNumber and custLastName for customers whose data satisfy the following
requests for lists of policyholders:
a. over 35 years old
b. at least 21 years old
c. no more than 30 years old
d. due no later than March 15 any year
e. due up to and including January 1, 2005
f. due by April 27, 2008
g. due as early as December 1, 2004
h. fewer than 11 accidents
i. no more than 5 accidents
j. no accidents
a.
if custAge > 35 then
print custPolicyNumber, custLastName
endif

b.
if custAge >=21 then
print custPolicyNumber, custLastName
endif

c.
if custAge <= 30 then
print custPolicyNumber, custLastName
endif

d.
if custDueMonth <= 2 then
print custPolicyNumber, custLastName
else
if custDueMonth = 3 then
if custDueDay <= 15 then
print custPolicyNumber, custLastName
endif
endif
endif

e.
if custDueYear < 2005 then
print custPolicyNumber, custLastName
else
if custDueYear = 2005 then
if custDueMonth = 1 then
if custDueDay = 1 then
print custPolicyNumber, custLastName
endif
endif
endif
endif

f.
if custDueYear < 2008 then
print custPolicyNumber, custLastName
else
if custDueYear = 2008 then
if custDueMonth < 4 then
print custPolicyNumber, custLastName
else
if custDueMonth = 4 then
if custDueDay < = 27 then
print custPolicyNumber, custLastName
endif
endif
endif
endif
endif

g.
if custDueYear < 2004 then
print custPolicyNumber, custLastName
else
if custDueYear = 2004 then
if custDueMonth < 12 then
print custPolicyNumber, custLastName
else
if custDueDay = 1 then
print custPolicyNumber, custLastName
endif
endif
endif
endif

h.
if custAccidents < 11 then
print custPolicyNumber, custLastName
endif

i.
if custAccidents <= 5 then
print custPolicyNumber, custLastName
endif

j.
if custAccidents = 0 then
print custPolicyNumber, custLastName
endif

8. Student files contain an ID number (four digits), last and first names (15 characters
each), and major field of study (10 characters). Plan a program that lists ID numbers
and names for all French or Spanish majors.
a.
b.
c.

Design the print chart for this program.


Draw the hierarchy chart for this program.
Create a decision table to use while planning the logic for

this program.

d.
e.

Draw the flowchart for this program.


Write the pseudocode for this program.

a. Print chart:
1 1
1 2 3 4 5 6 7 8 9 0 1
1
F r e
2
3 I D N u mb e r
4
5
9 9 9 9
6
9 9 9 9
7
9 9 9 9
8
9
10
11

1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4
2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
n c h a n d S p a n i s h Ma j o r s
L a s t

N a me

XXXXXXXXXXXXXXX
XXXXXXXXXXXXXXX
XXXXXXXXXXXXXXX

F i r s t

N a me

XXXXXXXXXXXXXXX
XXXXXXXXXXXXXXX
XXXXXXXXXXXXXXX

b. Hierarchy chart:
main( )

housekeeping( )

mainLoop( )

finishUp( )

headings( )

c. Decision table:
Condition
stuMajor = French
stuMajor = Spanish
print
dont print

Outcome
T
T
T
F
X
X

F
T
X

F
F
X

d. Flowchart:

e. Pseudocode:
start
perform housekeeping( )
while not eof
perform mainLoop( )
endwhile
perform finishUp( )
stop
housekeeping( )
define variables
open files
perform headings( )
read stuRec
return
headings( )
print heading1
print heading2
return
mainLoop( )
if stuMajor = "French" then
print stuId, stuLast, stuFirst
else
if stuMajor = "Spanish" then
print stuId, stuLast, stuFirst
endif
endif
read stuRec
return
finishUp( )
close files
return

9.

A florist wants to send coupons to her best customers, so she needs a list of names
and addresses for customers who placed orders more than three times last year or
spent more than $200 last year. The input file description follows:
File name: FLORISTCUSTS
FIELD DESCRIPTION
POSITIONS
TYPE
DECIMALS
Customer ID
13
Numeric
0
First Name
416
Character
Last Name
Street Address
Orders Last Year

1730
3151
5255
0
56-62
2

Amount Spent

Character
Character
Numeric
Numeric

Last Year
(Note: To save room, dont include city or state. Assume all the florists best
customers are in town.)
a.
Design the print chart for this program.
b.
Draw the hierarchy chart for this program.
c.
Create a decision table to use while planning the logic for
this program.
d.
Draw the flowchart for this program.
e.
Write the pseudocode for this program.
a. Print chart:
11111111112222222222 333333333344444444445555
12345678901234567890123456789 012345678901234567890123
1
Be s t Cu s t o m e r s
2
3
F i r s t N a me
L a s t N a me
Ad d r e s s
4
5 XXXXXXXXXXXXX
XXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXX
6 XXXXXXXXXXXXX
XXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXX
7 XXXXXXXXXXXXX
XXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXX
8
9
10
11

b. Hierarchy chart:
main( )

housekeeping( )

headings( )

mainLoop( )

finishUp( )

c. Decision table:
Condition
floOrders > orderLimit
floAmount > orderSpent
print
dont print

d. Flowchart:

Outcome
T
T
X

T
F
X

F
T
X

F
F
X

e. Pseudocode:
start
perform housekeeping( )
while not eof
perform mainLoop( )
endwhile
perform finishUp( )
stop
housekeeping( )
define variables
open files
perform headings( )
read floRec
return
headings( )
print heading1
print heading2
return
mainLoop( )
if floOrders > orderLimit then
print floFirst, floLast, floAddress
else
if floAmount > orderSpent then
print floFirst, floLast, floAddress
endif
endif
read floRec
return
finishUp( )
close files
return

10. A carpenter needs a program that computes the price of any desk a customer orders
based on the following input fields: order number, desk length and width (three
digits each, no decimals), type of wood (20 characters), and number of drawers (two
digits). The price is computed as follows:

The charge for all desks is a minimum $200.

If the surface (length * width) is over 750 square


inches, add $50.

If the wood is mahogany add $150; for oak add


$125. No charge is added for pine.

For every drawer in the desk, there is an additional


$30 charge.
a.
Design the print chart for this program.
b.
Draw the hierarchy chart for this program.
c.
Create a decision table to use while planning the logic for
this program.
d.
Draw the flowchart for this program.
e.
Write the pseudocode for this program.

a. Print chart:
1 1 1 1 1
1 2 3 4 5 6 7 8 9 0 1 2 3 4
1
De s k
P r i c e s
2
3 N u mb e r
P r i c e
4
5
9 9 9
9 9 9 . 9
6
9 9 9
9 9 9 . 9
7
9 9 9
9 9 9 . 9
8
9
10
11

1 1 1 1 1 2
5 6 7 8 9 0

9
9
9

b. Hierarchy chart:
main( )

housekeeping( )

headings( )

mainLoop( )

finishUp( )

c. Decision table:
Condition
surface > 750
wood =
"Mahogany"
wood = "Oak"
priceBeforeDrawers
= 200
priceBeforeDrawers
= 250
priceBeforeDrawers
= 325
priceBeforeDrawers
= 350
priceBeforeDrawers
= 375
priceBeforeDrawers
= 400

Outcome
T
T

T
T

T
F

T
F

F
T

F
T

F
F

F
F

F
X

X
X
X(impossible) X
X
X
X
(impossible)

d. Flowchart:

e. Pseudocode:
start
perform housekeeping( )
while not eof
perform mainLoop( )
endwhile
perform finishUp( )
stop
housekeeping( )
define variables
open files
perform headings( )
read deskRec
return
headings( )
print heading1
print heading2
return
mainLoop( )
charge = minimum
if deskLength * deskWidth > sizeLimit then
charge = charge + sizeLimitPremium
endif
if deskWood = "mahogany" then
charge = charge + mahoganyPremium
else
if deskWood = "oak" then
charge = charge + oakPremium
endif
endif
charge = charge + deskDrawers * perDrawer
print deskNumber, charge
read deskRec
return
finishUp( )
close files
return

11. A company is attempting to organize carpools to save energy. Each input record
contains an employees name and town of residence. Ten percent of the companys
employees live in Wonder Lake. Thirty percent of the employees live in Woodstock.
Because these towns are both north of the company, the company wants a list of
employees who live in either town so it can recommend that these employees drive to
work together.
a.
Design the print chart for this program.
b.
Draw the hierarchy chart for this program.
c.
Create a decision table to use while planning the logic for
this program.
d.
Draw the flowchart for this program.
e.
Write the pseudocode for this program.
a. Print Chart
1 2 3 4
1
E mp
2
3 I D N
4
5 XXXX
6 XXXX
7
8
9
10
11

1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4
5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
l o y e e s
I n
Se l e c t e d
Ci t i e s
u mb e r
XXXXX
XXXXX

L a s t

N a me

XXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXX

b. Hierarchy chart:
main( )

housekeeping( )

headings( )

mainLoop( )

finishUp( )

c. Decision table:
Condition
empCity =Woodstock
empCity =Wonder Lake
print
dont print

d. Flowchart:

Outcome
T
T
X
(impossible)

T
F
X

F
T
X

F
F
X

e. Pseudocode:
start
perform housekeeping( )
while not eof
perform mainLoop( )
endwhile
perform finishUp( )
stop
housekeeping( )
define variables
open files
perform headings( )
read empRec
return
headings( )
print heading1
print heading2
return
mainLoop( )
if empCity = "Woodstock" then
print empId, empLast
else
if empCity = "Wonder Lake" then
print empId, empLast
endif
endif
read empRec
return
finishUp( )
close files
return

12. A supervisor in a manufacturing company wants to produce a report showing which


employees have increased their production this year over last year, so that she can
issue them a certificate of commendation. She wants to have a report with three
columns: last name, first name, and either the word UP or blanks printed under the
column heading PRODUCTION. UP is printed when this years production is a
greater number than last years production. Input exists as follows:
PRODUCTION FILE DESCRIPTION
File name: PRODUCTION
FIELD DESCRIPTION
POSITIONS
DATA TYPE DECIMALS
Last Name
120
Character
First Name
2130
Character
Last Year's Production
3134
Numeric
0
This Year's Production
3538
Numeric
0
a.
Design the print chart for this program.
b.
Draw the hierarchy chart for this program.
c.
Create a decision table to use while planning the logic for
this program.
d.
Draw the flowchart for this program.
e.
Write the pseudocode for this program.
a. Print chart:
1
2 2 2 2
1 2 3 4 5 6 7 8 9 0 111213141516171819201 2 3 4
1
E mp l o y e e
Pr o d u
2
3
L a s t
N a me
Fi
4
5 XXXXXXXXXXXXXXXXXXXX
XX
6 XXXXXXXXXXXXXXXXXXXX
XX
7
8
9
10
11

2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4
5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
c t i o n Re p o r t
r s t

N a me

XXXXXXXX
XXXXXXXX

Pr o d u c t i o n
XX
XX

b. Hierarchy chart:
main( )

housekeeping( )

headings( )

mainLoop( )

finishUp( )

c. Decision table:
Condition
thisYearsProduction >
lastYearsProduction
print
dont print
d. Flowchart:

Outcome
T
F
X
X

e. Pseudocode:
start
perform housekeeping( )
while not eof
perform mainLoop( )
endwhile
perform finishUp( )
stop
housekeeping( )
define variables
open files
perform headings( )
read empRec
return
headings( )
print heading1
print heading2
return
mainLoop( )
if empThisYear > empLastYear then
print empLast, empFirst, "UP"
else
print empLast, empFirst
endif
read empRec
return
finishUp( )
close files
return

13. A supervisor in the same manufacturing company as described in Exercise 12 wants


to produce a report from the PRODUCTION input file showing bonuses she is
planning to give based on this years production. She wants to have a report with
three columns: last name, first name, and bonus. The bonuses will be distributed as
follows.
If this years production is:

1,000 units or fewer, 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 up, the bonus is $200


a.
Design the print chart for this program.
b.
Draw the hierarchy chart for this program.
c.
Create a decision table to use while planning the logic for
this program.
d.
Draw the flowchart for this program.
e.
Write the pseudocode for this program.
a. Print chart:
1 1 1 1 1 1 1
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6
1
E mp l o y
2
3
L a s t
N a me
4
5 XXXXXXXXXXXXXXXX
6 XXXXXXXXXXXXXXXX
7
8
9
10
11

1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4
7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
e e
Pr o d u c t i o n Re p o r t
Fi r s t
XXXX
XXXX

N a me

XXXXXXXXXX
XXXXXXXXXX

Bo n u s
9 9 9
9 9 9

b. Hierarchy chart:
main( )

housekeeping( )

headings( )

mainLoop( )

finishUp( )

c. Decision table:
Condition
empThisYear <= 1000
empThisYear <= 3000
empThisYear <= 6000
empThisYear > 6000
bonus = 200
bonus = 100
bonus = 50
bonus = 25

Outcome
T T T
T T T
T T F
T F T

T
T
F
F

T
F
T
T

T
F
T
F

T
F
F
T

T
F
F
F

F
T
T
T

F
T
T
F

F
T
F
T

F
T
F
F

F
F
T
T

F
F
T
F
X

X
X

F
F
F
T
X

F
F
F
F

d. Flowchart:

e. Pseudocode:
start
perform housekeeping( )
while not eof
perform mainLoop( )
endwhile
perform finishUp( )
stop
housekeeping( )
define variables
open files
perform headings( )
read empRec
return
headings( )
print heading1
print heading2
return
mainLoop( )
if empThisYear <= 1000 then
bonus = 25
else
if empThisYear <= 3000 then
bonus = 50
else
if empThisYear <= 6000 then
bonus = 100
else
bonus = 200
endif
endif
endif
print empLast, empFirst, bonus
read empRec
return
finishUp( )
close files
return

14.

Modify Exercise 13 to reflect the following new facts, and have the program
execute as efficiently as possible:
o
Only employees whose production this year is
higher than last year will receive bonuses. This is true for approximately 30%
of the employees.
o
Sixty percent of employees produce over 6,000
units per year, 20% produce 3,001 to 6,000, 15% produce 1,001 to 3,000 units,
and only 5% produce fewer than 1,001.
a.
Design the print chart for this program.
b.
Draw the hierarchy chart for this program.
c.
Create a decision table to use while planning the logic for
this program.
d.
Draw the flowchart for this program.
e.
Write the pseudocode for this program.

a. Print chart:
1 1 1 1 1 1 1
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6
1
E mp l o y
2
3
L a s t
N a me
4
5 XXXXXXXXXXXXXXXX
6 XXXXXXXXXXXXXXXX
7
8
9
10
11

1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4
7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
e e
Pr o d u c t i o n Re p o r t
Fi r s t
XXXX
XXXX

N a me

XXXXXXXXXX
XXXXXXXXXX

Bo n u s
9 9 9
9 9 9

b. Hierarchy chart:
main( )

housekeeping( )

headings( )

mainLoop( )

finishUp( )

c. Decision table:
Condition
empThisYear >
empLastYear
empThisYear > 6000
empThisYear > 3000
empThisYear > 1000
bonus = 200
bonus = 100
bonus = 50
bonus = 25
No Bonus

Outcome
T T T T T T

T T T T F F F F T
T T F F T T F F T
T F T F T F T F T
X
X
X
X
X

T
T
F

T
F
T

T
F
F

F
T
T

F
T
F

F
F
T

F
F
F

X X X X X X X

d. Flow chart

e. Pseudocode:
start
perform housekeeping( )
while not eof
perform mainLoop( )
endwhile
perform finishUp( )
stop
housekeeping( )
define variables
open files
perform headings( )
read empRec
return
headings( )
print heading1
print heading2
return
mainLoop( )
if empThisYear > empLastYear then
if empThisYear > 6000 then
bonus = 200
else
if empThisYear > 3000 then
bonus = 100
else
if empThisYear > 1000 then
bonus = 50
else
bonus = 25
endif
endif
endif
else
bonus=0
endif
print empLast, empFirst, bonus
read empRec
return

15. The Richmond Riding Club wants to assign the title of Master or Novice to each of
its members. A member earns the title of Master by accomplishing two or more of
the following:

Participating in at least eight horse shows

Winning a first or second place ribbon in at least


two horse shows, no matter how many shows the member has participated in

Winning a first, second, third or fourth place ribbon


in at least four horse shows, no matter how many shows the member has
participated in
Create a report that prints each club member's name along with the designation
"Master" or "Novice". Input exists as follows:
PRODUCTION FILE DESCRIPTION
File name: RIDING
FIELD DESCRIPTION
POSITIONS
DATA TYPE
DECIMALS
Last Name
115
Character
First Name
1625
Character
Number of shows
2628
Numeric
0
First place ribbons
2931
Numeric
0
Second place ribbons
32-34
Numeric
0
Third place ribbons
35-37
Numeric
0
Fourth place ribbons
38-40
Numeric
0
a.
Design the print chart for this program.
b.
Draw the hierarchy chart for this program.
c.
Create a decision table to use while planning the logic for
this program.
d.
Draw the flowchart for this program.
e.
Write the pseudocode for this program.
a. Print chart:

b. Hierarchy chart:
main( )

housekeeping( )

mainLoop( )

finishUp( )

headings( )

c. Decision Table:
Condition
ridingShows >= 8
firstOrSecond >= 2
firstThroughFourth
>= 4
title = "Master"
title = 'Novice"

Outcome
T
T
T
T
T
F

T
F
T

T
F
F

F
T
T

F
T
F

F
F
T

F
F
F

X
X

d. Flow Chart

e. Pseudocode:
start
perform housekeeping( )
while not eof
perform mainLoop( )
endwhile
perform finish( )
stop
housekeeping( )
declare variables
open files
perform headings( )
read ridingRec
return
headings( )
print heading1
print heading2
return
mainLoop( )
count = 0
if ridingShows .= 8 then
count = count + 1
end if
firstOrSecond = ridingFirst + ridingSecond
firstThroughFourth = firstOrSecond + ridingThird + ridingFourth
if firstOrSecond >= 2 then
count = count + 1
end if
if firstThroughFourth >= 4 then
count = count + 1
endif
if count >= 2 then
title = "Master"
else
title = "Novice"
endif
print ridingFirstName, ridingLastName, title
read ridingRec
return
finish( )
close files
return

Вам также может понравиться