Chapter 2

advertisement
Chapter 2
Getting Started With Program
Flowcharts, Arithmetic, and
Logical Operations
Programming Logic for Business
Copyright 2001 Laura Saret
Laura Saret EdD
Chapter Outline
 What is a Program Flowchart, and Why do
Programmers Use Them to Develop Program Logic?
 What are the Flowchart Symbols?
 What Are the Rules for Drawing Flowcharts?
 Example: Open, Read, Move, Write, Stop, and
Close Instructions; Input Areas, Output Areas, and Work Areas
 Example: Looping and Checking for End of File
 How are Addresses and Names Used in Primary Storage?
 Example: Naming and Defining Areas in Storage
 Example: Assignment Instructions, Counters, Work Areas, and
Connectors
Chapter Outline (continued)
Example: Counters as Totals
What Are Arithmetic Operations and How Are They Used?
Example: Arithmetic Operations
What Are Relational Operations and How Are They Used?
Example: Relational Operations
What is the Difference Between Branching and Using
Subroutines?
 Example: Screen Output, Compare Areas, Subroutines,
Literals (Constants)Versus Field Names (Variables)






Chapter objectives
After completing this chapter you should be able to.…
 Explain what a program flowchart is and what the reasons for
and disadvantages are of using program flowcharts to plan
logic.
 Recognize and know when to use appropriate program
flowchart symbols.
 Write instructions that contain arithmetic and logical
operations.
 Draw simple flowcharts that include decision making, loops,
subroutines, calculations, counters, and accumulators.
 Describe how the following instructions work and know when
to use them: Open, Read, Move, Assignment, Write, Close,
Stop, Branch (Go To), Do (Call, Gosub, Perform) a Subroutine,
and Clear Screen.
 Use field names (variables) and literals (constants).
What is a program flowchart?
 A tool used by programmers to
develop program logic
 Logic diagram
 Focuses on the sequence of data
transformations from the time
data are input until they are
output as information
Start
Open
Files
Read a
Record
EOF?
Yes
No
Write a
Line
Close
Files
Stop
Why do programmers use flowcharts
to develop program logic?
 Flowcharts are a good
visual reference of what
the program will do
 Serve as program
documentation and as a
communications tool
 Allow the programmer
to test alternative
solutions
 Desk check
What are the flowchart
symbols?
Terminal Symbol
Designates the beginning or end of a
program or routine
START
STOP
HEADINGS
RETURN
Input/Output (I/O) Symbol
Denotes an operation involving an
input or output device
OPEN
FILES
WRITE
A LINE
READ A
RECORD
CLOSE
FILES
Process Symbol
Used for move instructions and
arithmetic instructions
MOVE
SCORE1 TO
ACCUMULATOR
AVERAGE =
(SCORE1 +
SCORE2) / 2
Decision Symbol
Designates that different logic paths
will be followed based on a condition
occurring in a program
CODE = ?
IS A = B?
Yes
No
1
2
3
4
5
Preparation Symbol
Assigns initial values to areas in
storage and does whatever else is
necessary to get ready for processing
COUNTER
=
0
Annotation Symbol
Describes or shows comments
on the flowchart
AVERAGE =
(SCORE1 +
SCORE2) / 2
CALCULATE
AVERAGE
Flowline Symbol
Links other symbols and
indicates the sequence of
operations
•Normal flow is top to bottom and
left to right
•Arrowheads must be used when
the flow is other than the normal
flow
Connector Symbol
Connects parts of the flowchart when
the use of flowlines would be
confusing or otherwise undesirable
X:3
A
=
<>
Off-page Connector Symbol
Connects parts of the flowchart from
one page to another
COMPARE
X TO 3
<>
=
p. 2
B
Subroutine Symbol
Subroutines can either be part of your
program (internal) or as instructions
in another program (external)
DO
HEADINGS
Internal
subroutine
symbol
GET
CURRENT
DATE FROM
SYSTEM
External
subroutine
symbol
Rules for Drawing Flowcharts
 Draw top to bottom and left to right
 Be neat!
 Use a pencil
 Use a template or computer software
More Rules...
 Avoid intersecting flowlines
START
B
START
A
C
B
A
C
STOP
STOP
More rules
 Avoid multiple flowlines entering a symbol
Example in Section 2.4
(page 34)
 Instructions
 Open
 Read
 Move
 Write
 Close
 Stop
 Areas in storage
 Input areas
 Output areas
 Work areas
Start
Open
Files
Read a
Record
Write a
line
Close
Files
Stop
Start and Stop
 Start
 First instruction of flowchart
Start
Open
Files
 Stop
 Last instruction executed
 Start and Stop instructions are
in terminal symbols
Read a
Record
Write a
line
Close
Files
Stop
Open and Close
 Opening a file
 Before a file can be accessed, it must be
opened
 Ensures that the file can be accessed
 Depending on the programming
language, not all files need to be
opened by the programmer--some are
opened automatically by the language
 Closing a file
 Close instruction tells the computer
your are through accessing the file
 Some languages will automatically
close files
 Writes the end-of-file record on output
files
Start
Open
Files
Read a
Record
Write a
line
Close
Files
Stop
Read
 Copies the content of the record
contained in secondary storage into the
primary storage of the computer
 The record is not physically moved from
secondary to primary storage
 Suppose the input record contains the
name MARY SMITH. How does the
computer know where in primary
storage to put the record?
Start
Open
Files
Read a
Record
Write a
line
Close
Files
Stop
Primary Storage
Instructions
Input Area
Data
Output Area
Work Area
MARY SMITH
 When the read instruction is executed, the name
MARY SMITH is stored in the input area
Write (Print, Display)
 Copies the content of the
record contained in the
output area of primary
storage to secondary
storage
 How does the record get
from the input area to the
output area?
Start
Open
Files
Read a
Record
Write a
line
Close
Files
Stop
Move
 Some languages
automatically do the
Move as part of the Write
instruction.
 Other languages require
that the Move be done
explicitly.
Read a
Record
Move content
of input area
to output area
Write a
line
Move Content of Input Area to
Output Area
 A copy of the record stored in the input area is
put in the output area
 The record is not physically moved
 The content of the input area remains unchanged after
the move is executed
Input Area
Output Area
MARY SMITH
MARY SMITH
Work Area
 After the move instruction is executed, both the
input and output areas contain the content of the
record input by the read instruction
Move Instruction
MOVE CONTENT OF AREA1 TO AREA2
Content of storage before MOVE
Area1
Area2
abcdefg
Content of storage after MOVE
Area1
Area2
abcdefg
abcdefg
Loops
 To process more than one record
from a file, it is necessary to loop
or repeat the instructions for each
record of the file
 What is wrong with the flowchart
shown to the right?
 It contains an endless or infinite
loop
Start
Open
Files
Read a
Record
Write a
Line
Terminating a Loop at EOF
(Example in Section 2.5—page 37)
 This loop terminates at end of
file (EOF)
 How does the computer
recognize EOF?
Start
 EOF marker or record on the file
 EOF record does not contain
data to be processed
 Placed on the file by the CLOSE
instruction
Open
Files
Read a
Record
EOF?
Yes
No
Write a
line
Close
Files
 Some languages check for
EOF…
Stop
 As part of the read instruction
 After the read instruction
 Before the read instruction
 Notice that the EOF record is
not written to the
output
Let’s Look at This Flowchart with
Some Data
Input File
Carol Jessel
Ron Patel
Jason Smith
Linda Wu
EOF
Start
Open
Files
Read a
Record
EOF?
Yes
No
Write a
line
Close
Files
Report
Input and output
areas at start of
processing
Stop
Input Area
Output Area
Let’s Look at This Flowchart with
Some Data
Input File
Carol Jessel
Ron Patel
Jason Smith
Linda Wu
EOF
Start
Open
Files
Read a
Record
EOF?
Yes
No
Write a
line
Close
Files
Report
Content of
memory after first
read is executed
Stop
Input Area
Carol Jessel
Output Area
Let’s Look at This Flowchart with
Some Data
Input File
Carol Jessel
Ron Patel
Jason Smith
Linda Wu
EOF
Start
Open
Files
Read a
Record
EOF?
Yes
No
Write a
line
Close
Files
Stop
Report
Carol Jessel
Content of
memory after first
write is executed
Input Area
Output Area
Carol Jessel
Carol Jessel
Let’s Look at This Flowchart with
Some Data
Input File
Start
Carol Jessel
Ron Patel
Jason Smith
Linda Wu
EOF
Open
Files
Read a
Record
EOF?
Yes
No
Write a
line
Close
Files
Stop
Report
Carol Jessel
Content of memory
after second read is
executed
Input Area
Output Area
Ron Patel
Carol Jessel
Let’s Look at This Flowchart with
Some Data
Input File
Carol Jessel
Ron Patel
Jason Smith
Linda Wu
EOF
Start
Open
Files
Read a
Record
EOF?
Yes
No
Write a
line
Close
Files
Stop
Report
Carol Jessel
Ron Patel
Content of
memory after
second write is
executed
Input Area
Output Area
Ron Patel
Ron Patel
Let’s Look at This Flowchart with
Some Data
Input File
Carol Jessel
Ron Patel
Jason Smith
Linda Wu
EOF
Start
Open
Files
Read a
Record
EOF?
Yes
No
Write a
line
Close
Files
Stop
Report
Carol Jessel
Ron Patel
Content of memory
after third read is
executed
Input Area
Output Area
Jason Smith
Ron Patel
Let’s Look at This Flowchart with
Some Data
Input File
Carol Jessel
Ron Patel
Jason Smith
Linda Wu
EOF
Start
Open
Files
Read a
Record
EOF?
Yes
No
Write a
line
Close
Files
Stop
Report
Carol Jessel
Ron Patel
Jason Smith
Content of
memory after third
write is executed
Input Area
Output Area
Jason Smith
Jason Smith
Let’s Look at This Flowchart with
Some Data
Input File
Carol Jessel
Ron Patel
Jason Smith
Linda Wu
EOF
Start
Open
Files
Read a
Record
EOF?
Yes
No
Write a
line
Close
Files
Stop
Report
Carol Jessel
Ron Patel
Jason Smith
Content of memory
after fourth read is
executed
Input Area
Output Area
Linda Wu
Jason Smith
Let’s Look at This Flowchart with
Some Data
Input File
Carol Jessel
Ron Patel
Jason Smith
Linda Wu
EOF
Start
Open
Files
Read a
Record
EOF?
Yes
No
Write a
line
Close
Files
Stop
Report
Carol Jessel
Ron Patel
Jason Smith
Linda Wu
Content of
memory after
fourth write is
executed
Input Area
Output Area
Linda Wu
Linda Wu
Let’s Look at This Flowchart with
Some Data
Input File
Carol Jessel
Ron Patel
Jason Smith
Linda Wu
EOF
Start
Open
Files
Read a
Record
EOF?
Yes
No
Write a
line
Close
Files
Stop
Report
Carol Jessel
Ron Patel
Jason Smith
Linda Wu
Content of memory
after fifth read is
executed
Input Area
Output Area
EOF
Linda Wu
Using Names and Addresses in
Primary Storage
 Primary storage is divided into
many storage locations
 Each location is assigned a
number or address
 Programmers don’t like to use
numeric addresses
 Ties the program to a
particular computer
 Programmers use names
 Field names
 Data names
 Variable names
 Identifiers
 When the program is translated into machine language,
names are translated into addresses
Rules for Naming Storage Locations
 Each language has its own naming rules
 All names must begin with an alphabetic character
 Once you name a field, you cannot change the name
 Example: If you name a storage location ACCOUNT, you
can’t call it ACCT in the same program
 Most languages require that storage locations be
defined before they are used
 Name of the location
 Size of the location
 Type of data the location will contain
 We will use data dictionaries to define data
Naming and defining areas in storage
(example in section 2.7)
 Suppose we have a file that consists of one record
for each supplier of a company. Each record
contains two fields
 Supplier-Name
 Supplier-Address
 We will use the file to produce a list of suppliers
 Supplier-Name
Data Dictionary
Input Area—SUPPLIER-INPUT-FILE
Name
Description
Type
Supplier-Name
Supplier-Address
Supplier’s name
Supplier’s address
Output Area—SUPPLIER-REPORT
Nonnumeric
Nonnumeric
Start
Open
Files
Supplier-Name
Supplier-Address
Read a
Record
EOF?
Yes
Close
Files
Stop
No
Write
Supplier-Name
Instead of the instruction Write a Record, we use the
instruction Write Supplier-Name
What Happens to Supplier-Address?
 When a record is read, both Supplier-Name and
Supplier-Address are put in the input area—you
cannot read only part of an input record
 Only Supplier-Name is written
 Supplier-Address stays in the input area and is
“over-written” when the next record is read
ABC Corporation
XYZ
Company
Chicago, Illinois
Springfield,
Illinois
ABC Company
The Example in Section 2.8 (page 42)
uses…
 Assignment Instructions
 Counters
 Work Areas
 Connectors
Assignment Instructions
 Assign a value to a storage location
 Counter = 0
 Store 0 in the storage location named Counter
 Equivalent to the move instruction:
 Move 0 to Counter
X=Y
 Move the content of the storage location named Y to the
storage location named X
 Move Y to X
Y
X
An Assignment Instruction Tells
the Computer to…
 Put whatever is to the right of the equal sign in
the storage location named on the left of the
equal sign
 X = 15
Y=3-2
 COUNTER = 0
 COUNTER = COUNTER + 1
The Intersecting Lines Can Be
Replaced With Connectors
EOF?
No
Start
Write
Supplier-Name
Open
Files
Add 1 to
Counter
Counter
=0
Read a
Record
Yes
Supplier-Name
Supplier-Address
<
Counter
: 10
=
Close
Files
Stop
Connectors
EOF?
No
Start
Write
Supplier-Name
Open
Files
Add 1 to
Counter
Counter
=0
A
A
Read a
Record
Yes
Supplier-Name
Supplier-Address
<
Counter
: 10
=
Close
Files
Stop
Now Let’s Examine the Program
EOF?
No
Start
Write
Supplier-Name
Open
Files
Add 1 to
Counter
Counter
=0
A
A
Read a
Record
Yes
Supplier-Name
Supplier-Address
<
Counter
: 10
=
Close
Files
WHAT IS
COUNTER?
Stop
Data Dictionary
Input Area—SUPPLIER-INPUT-FILE
Name
Description
Type
Supplier-Name
Supplier-Address
Supplier’s name
Supplier’s address
Nonnumeric
Nonnumeric
Output Area—SUPPLIER-REPORT
Work Area
COUNTER is an arbitrary and meaningful
name assigned by the programmer to a
location in the work area of primary storage
Name
Description
Type
Counter
Counter used to count
number of records processed
Numeric
Initial Value
0
How Many Lines are Written?
EOF?
Start
Open
Files
No
Counter is
given an
initial value
of 0
Write
Supplier-Name
Add 1 to
Counter
Counter
=0
A
A
Read a
Record
Supplier-Name
Supplier-Address
<
Counter
: 10
=
Close
Files
When Counter is
equal to 10, we close
files and stop
Yes
Stop
Each time
we write
a record,
we add 1
to counter
Counters as Totals
(Example in Section 2.9—page 44)
Must do three things:
Start
1. Give the counter
(Number-Of-Suppliers)
an initial value of 0
Open
Files
2. Increment the counter
for each input record
Number-OfSuppliers = 0
Read a
Record
Supplier-Name
Supplier-Address
Write
Number-Of
Yes -Suppliers
No
Write
Supplier-Name
EOF?
Add 1 to
Number-Of
-Suppliers
Close
Files
3. Print the total (the
value of the counter)
Stop
The Following Instructions Don’t
Work. Why?
Supplier-Name
Read a
Record
Supplier-Address
Add 1 to
Number-OfSuppliers
EOF?
No
Yes
Arithmetic Operators
 Addition
 Subtraction
 Multiplication
 Division
 Integer Division
 Modulo
 Exponentiation
+
*
/
\
MOD
^
Examples
5+8
13
 12 - 3.4
8.6
Warning: Be sure to use
an operator for
multiplication
5*3
3*A
6/4
3A
6\4
3(A)
15
1.5
1
 6 MOD 4
2
5^3
125
will generate a syntax
error
Order (Hierarchy) of Operations
 Evaluate the following:
8+4/2
 Is the result 6? (first add 8 and 4; then divide by 2)
 Is the result 10? (first divide 4 by 2; then add 8)
 Hierarchy of operations
 Read from left to right and do all exponentiations in the
order they occur
 Read from left to right and do all multiplications and/or
divisions in the order they occur
 Read from left to right and do all integer divisions in the
order they occur
 Read from left to right and do all modulo arithmetics in
the order they occur
 Read from left to right and do all additions and/or
subtractions in the order they occur
Practice







 exponentiations
 multiplications and/or divisions
 integer divisions
 modulo arithmetics
 additions and/or subtractions
3 * 5 MOD 2 + 25 / 5 ^ 2 + 18 * 2 / 4 - 3 + 1 * 2 + 6 \ 5
3 * 5 MOD 2 + 25 / 5 ^ 2 + 18 * 2 / 4 - 3 + 1 * 2 + 6 \ 5
3 * 5 MOD 2 + 25 / 25
+ 18 * 2 / 4 - 3 + 1 * 2 + 6 \ 5
15 MOD 2 + 1
+9
-3+2
+6\5
15 MOD 2 + 1
+9
-3+2
+1
1
+1
+9
-3+2
+1
11
Parentheses Change the Order
of Operations—They are Evaluated First


3+5/4
3 + 1.25
4.25
(3 + 5) /4
8
/4
2
Parentheses Can be Nested—
Innermost Parentheses are Evaluated First
81
81
81
81
3
30
/ (9 * 3) + 3 ^ (2 + 2) / (2 + 3 * (6 / 2) - 8)
/ (9 * 3) + 3 ^ (2 + 2) / (2 + 3 * 3
- 8)
/ 27
+3^4
/3
/ 27
+ 81
/3
+ 27
Examples: From Algebraic to Computer
Expressions
Algebraic Expression
A
2 +
B
5
A+
X
3
Computer Expression
A^2+B^3
(A + 5 / X) ^ .5
Note: Raising a value to the .5
power is the same as taking the
square root.
Examples: From Algebraic to Computer
Expressions
Algebraic Expression
XY
17
17
-
Computer Expression
X * Y / (17 – W ^ 3)
W
- W
XY
3
3
(17 – W ^ 3) / (X * Y)
Examples: From Algebraic to Computer
Expressions
Algebraic Expression
A+B
C- D
A +B
C
A +
B
C
Computer Expression
(A + B) / (C – D)
(A + B) / C
A+B/C
Example: Arithmetic Operations
(Section 2.11—page 48)
Start
Open
Files
Read a
Record
Salesperson-Name
Salesperson-Num
Base-Salary
Comm-Rate
Sales
EOF?
Close
Yes Files
No
Comm-Amt =
Sales *
Comm-Rate
Stop
Gross-Salary =
Base-Salary +
Comm-Amt
Write a
line
Salesperson-Name,
Salesperson-Num and
Base-Salary come
from the input.
Where do Comm-Amt
and Gross-Salary
come from?
Salesperson-Name
Salesperson-Num
Base-Salary
Comm-Amt
Gross-Salary
Comm-Amt and
Gross-Salary are
defined as work
areas. Their
values are
calculated in the
program.
Relational Operators
 Greater than
=
<
>
 Less than or equal to
<=
 Greater than or equal to
>=
<>
:
 Equals
 Less than
 Not equal to
 Compare
or
!=
Relational Operators
A
B
 Compare storage locations containing the same type of data
 Numbers to numbers
 Nonnumeric values to nonnumeric values
 When comparing numbers, the value stored in A is less than
the value stored in B if A is to the left of B on a number line
5<7
 -1 < 0
 3.2 < 3.25
 3 + 5 = 2 + 6 Do arithmetic first--then determine equality
 When comparing nonnumeric values, the value stored in A is
less than the value stored in B if A precedes B alphabetically
blanks or spaces < digits < uppercase letters < lowercase letters
 CAT < CATCH
 A SMITH < ABE SMITH
 SMITH < Smith
 Roger1 < Roger23
Flowcharts Show Relational Operations with
Decision Symbols
Example:
If SalesAmount is greater than 1000 then branch to connector A;
otherwise branch to connector B
Is
SalesAmount
A
>
Yes
1000?
Is
SalesAmount
B
>
No
1000?
Yes
No
A
B
Is
SalesAmount
B
<=
Yes
1000?
SalesAmount
:
1000
<=
No
A
B
>
A
Example–
Relational
Operations
(section 2.13 page 51)
Start
Open
Files
Read a
Record
EOF?
 Commission is
calculated based
on the amount
of sales from
the input record
 Where are
Comm-Amt and
Gross-Salary
defined? Why?
Yes
No
Sales:
1000
>
<=
Salesperson-Name
Salesperson-Num
Base-Salary
Sales
Close
Files
Stop
Comm-Amt =
Sales * .10
Comm-Amt =
Sales * .05
Gross-Salary =
Base-Salary +
Comm-Amt
Write a
Line
Salesperson-Name
Salesperson-Num
Base-Salary
Comm-Amt
Gross-Salary
Branching
 The flow of a program goes from
one instruction to the next
unless something changes the
order
 Branch instructions change the
flow of logic in a program
 Unconditional branches
 Conditional branches
Unconditional
branch
Start
Conditional
branch
Open
Files
Read a
Record
EOF?
Yes
No
Sales:
1000
>
<=
Salesperson-Name
Salesperson-Num
Base-Salary
Sales
Close
Files
Stop
Comm-Amt =
Sales * .10
Comm-Amt =
Sales * .05
Gross-Salary =
Base-Salary +
Comm-Amt
Write a
Line
Salesperson-Name
Salesperson-Num
Base-Salary
Comm-Amt
Gross-Salary
Subroutines (Functions)
 Another way to change of the flow of logic is to do
(CALL, PERFORM, GOSUB) a subroutine (function)
RoutineA
Do
RoutineA
Subroutine
Instructions
Return
 All subroutines start with a terminal symbol
containing the name of the routine and end with a
terminal symbol containing the word Return
Subroutines Can be Nested
RoutineA
RoutineB
Subroutine
Instructions
Do
RoutineA
Do
RoutineB
Return
Return
Subroutines Can be Internal or
External
 Internal subroutines are coded as part of the
program
 External subroutines are contained outside the
program
Example: Internal Subroutines
Calculations
Start
Sales
:
1000
<=
Open
Files
Read a
Record
EOF?
Yes
No
Salesperson-Name
Salesperson-Num
Base-Salary
Sales
Close
Files
Stop
Do
Calculations
Write a line
Comm-Amt =
Sales * .05
Gross-Salary =
Base-Salary +
Comm-Amt
Return
Salesperson-Name
Salesperson-Num
Base-Salary
Comm-Amt
Gross-Salary
Comm-Amt =
Sales * .10
>
Example From Section 2.15 (page 55)
 Screen output
 Compare areas
 Subroutines
 Literals (constants)
 Field names
(variables)
Highest Score = 100
Lowest Score = 15
Average Score = 58.40
This is a summary report
 Output is a screen report for a teacher
 Input consists of one record for each student in the
class. Each record contains a student name and the
score (0-100) that the student earned on a test
Highest Score = 100
Lowest Score = 15
Average Score = 58.40
Mainline routine
Start
The routine that goes from Start to Stop
Do
Initialize
Get ready for processing
How many times is the
Initialize routine done?
Read a
Record
Student-Name
Score
Do
EOF?
No
Yes
Do
Display
Close
Files
Process
Read and process
records until EOF
How many times is this
loop done?
Display report on screen
How many times is this
routine done?
Close files and stop
Stop
Initialize
Num-Students = 0
Total = 0
Average
High-Score = 0
Low-Score = 100
Assign
Names and initial
values in
work area
Open
Files
Initialize routine
Clear
Screen
Return
 Assign initial values in work area
 Num-Students and Total are needed to
calculate the average in Display
 Num-Students is
Num-Students = 0
a counter-- the
Total = 0
Process routine
Average
adds 1 to
High-Score = 0
Num-Students for Low-Score = 100
each input record
 Total is an accumulator--the Process
routine adds the score from the input
record to Total
 High-Score and Low-Score are compare
areas
 The computer cannot remember which
is the highest and lowest score it has
read
 We’ll look at them more when we
discuss Process
 Open files
 Clear screen
Initialize
Assign
Names and initial
values in
work area
Open
Files
Clear
Screen
Return
Let’s look at Process
Process
 This routine is done 1 time
for each input record
 High-Score was initialized to
0. Why?
 Low-Score was initialized to
100. Why?
Add 1 to
Num-Students
Add Score
to Total
Score:
High-Score >
<=
Score:
Low-Score <
>=
Return
Move Score
to
High-Score
Move Score
to
Low-Score
Let’s Desk Check Process
Process
 Sample Input
MARY JONES 100
CARY CARLSON 25
SARAH FISHER 82
JOHN CHIN 70
JERRY SCHMIDT 15
 Content of Work Area After
Initialize Routine Has Been
Completed
NUM-STUDENTS = 0
TOTAL = 0
HIGH-SCORE = 0
LOW-SCORE = 100
AVERAGE
Add 1 to
Num-Students
Add Score
to Total
Score:
High-Score >
<=
Score:
Low-Score <
>=
Return
Move Score
to
High-Score
Move Score
to
Low-Score
Let’s Desk Check Process
 Sample Input
MARY JONES 100
CARY CARLSON 25
SARAH FISHER 82
JOHN CHIN 70
JERRY SCHMIDT 15
 Content of Input Area After 1st
Record Has Been Read
NAME = MARY JONES
SCORE = 100
 Content of Work Area After 1st
Record Has Been Processed
NUM-STUDENTS = 1
TOTAL = 100
HIGH-SCORE = 100
LOW-SCORE = 100
AVERAGE
Process
Add 1 to
Num-Students
Add Score
to Total
Score:
High-Score >
<=
Score:
Low-Score <
>=
Return
Move Score
to
High-Score
Move Score
to
Low-Score
Let’s Desk Check Process
 Sample Input
MARY JONES 100
CARY CARLSON 25
SARAH FISHER 82
JOHN CHIN 70
JERRY SCHMIDT 15
 Content of Input Area After 2nd
Record Has Been Read
NAME = CARY CARLSON
SCORE = 25
 Content of Work Area After 1st
Record Has Been Processed
NUM-STUDENTS = 1
TOTAL = 100
HIGH-SCORE = 100
LOW-SCORE = 100
AVERAGE
 Content of Work Area After 2nd
Record Has Been Processed
NUM-STUDENTS = 2
TOTAL = 125
HIGH-SCORE = 100
LOW-SCORE = 25
AVERAGE
Process
Add 1 to
Num-Students
Add Score
to Total
Score:
High-Score >
<=
Score:
Low-Score <
>=
Return
Move Score
to
High-Score
Move Score
to
Low-Score
Let’s Desk Check Process
 Sample Input
MARY JONES 100
CARY CARLSON 25
SARAH FISHER 82
JOHN CHIN 70
JERRY SCHMIDT 15
 Content of Input Area After 3rd
Record Has Been Read
NAME = SARAH FISHER
SCORE = 82
 Content of Work Area After 2nd
Record Has Been Processed
NUM-STUDENTS = 2
TOTAL = 125
HIGH-SCORE = 100
LOW-SCORE = 25
AVERAGE
 Content of Work Area After 3rd
Record Has Been Processed
NUM-STUDENTS = 3
TOTAL = 207
HIGH-SCORE = 100
LOW-SCORE = 25
AVERAGE
Process
Add 1 to
Num-Students
Add Score
to Total
Score:
High-Score >
<=
Score:
Low-Score <
>=
Return
Move Score
to
High-Score
Move Score
to
Low-Score
Let’s Desk Check Process
 Sample Input
MARY JONES 100
CARY CARLSON 25
SARAH FISHER 82
JOHN CHIN 70
JERRY SCHMIDT 15
 Content of Input Area After 4th
Record Has Been Read
NAME = JOHN CHIN
SCORE = 70
 Content of Work Area After 3rd
Record Has Been Processed
NUM-STUDENTS = 3
TOTAL = 207
HIGH-SCORE = 100
LOW-SCORE = 25
AVERAGE
 Content of Work Area After 4th
Record Has Been Processed
NUM-STUDENTS = 4
TOTAL = 277
HIGH-SCORE = 100
LOW-SCORE = 25
AVERAGE
Process
Add 1 to
Num-Students
Add Score
to Total
Score:
High-Score >
<=
Score:
Low-Score <
>=
Return
Move Score
to
High-Score
Move Score
to
Low-Score
Let’s Desk Check Process
 Sample Input
MARY JONES 100
CARY CARLSON 25
SARAH FISHER 82
JOHN CHIN 70
JERRY SCHMIDT 15
 Content of Input Area After 5th
Record Has Been Read
NAME = JERRY SCHMIDT
SCORE = 15
 Content of Work Area After 4th
Record Has Been Processed
NUM-STUDENTS = 4
TOTAL = 277
HIGH-SCORE = 100
LOW-SCORE = 25
AVERAGE
 Content of Work Area After 5th
Record Has Been Processed
NUM-STUDENTS = 5
TOTAL = 292
HIGH-SCORE = 100
LOW-SCORE = 15
AVERAGE
Process
Add 1 to
Num-Students
Add Score
to Total
Score:
High-Score >
<=
Score:
Low-Score <
>=
Return
Move Score
to
High-Score
Move Score
to
Low-Score
Before Looking at Display, Let’s
Discuss Literals (Constants)
 Values displayed directly in an instruction
 Display “Highest Score = ” and High-Score
 Display 5
 “Highest Score = ” and 5 are literals (constants)
 High-Score is a variable (name of a storage
location)
Let’s Look at Display
 Why does the routine first check
to determine if Num-Students is
equal to 0?
 Why is the literal (constant)
“Input File Was Empty” in
quotation marks (“”)?
 Why is field name (variable)
High-Score not in quotation
marks?
 Field names are not shown in
quotation marks—Numeric
literals are shown in quotation
marks
 In the first instruction, 0 is a
constant, but it is not in
quotation marks. Why?
 Numeric constants are not
shown in quotation marks
 How many lines (including blank
lines) are displayed?
Display
Display
Num-Students
"Input File
:0
=
Was Empty"
>
Display
"Highest Score
=" and
High-Score
Display a
Blank Line
Display
"Lowest Score
=" and
Low-Score
Display a
Blank Line
Average = Total /
Num-Students
Display
"Average Score
=" and
Average
Return
Download