lesson 7 - WordPress.com

Download Report

Transcript lesson 7 - WordPress.com

JSP (Jackson Structured
Programming)
Lesson 7 – Program Concepts
JSP (Jackson Structured Programming)

Methodology developed by Michael Anthony
Jackson in 1970

Uses top-down methodology

3 structured constructs
◦ Sequence
◦ Selection
◦ Iteration/Repetition
Sequence
A sequence of operations is represented by boxes connected
with lines. In the example below, operation A consists of the
sequence of operations B, C and D
A seq
B
C
D
A end
Selection
A sequence of operations is represented by boxes connected with
lines. In the example below, operation A consists of the sequence of
operations B, C and D
IF C1 THEN
DO B
ENDDO
ELSE
IF C2 THEN
DO C
ENDDO
ELSE
IF C3 THEN
DO D
ENDDO
ENDIF
Iteration
An iteration is again represented with joined boxes. In addition
the iterated operation has a star in the top right corner of its box.
In the example below, operation A consists of an iteration of
zero or more invocations of operation B.
WHILE condition 1
DO B
ENDDO
Example: Sequence
Main
Control
Initial
Body
End
Example: Selection
Check Age
Module
C1
Teenage Module0
Where C1 is Age < 21
Adult Module0
Example: Iteration
Main Process
While C1
C1 is not end of file
Detail Process
JSP

Function list
◦ Sequence of actions listed

Condition list
◦ Associated with selections and iterations
Note: function & condition lists are listed separately from the
structure diagram and are cross-referenced
JSP

Stepwise Refinement
◦ A process to sub-divide (refine) the main program
function into subsidiary functions
◦ Increasing the details at each level until the lowest
functions are represented
JSP
Case Study
A program is needed to help a college to grade its students. A total weighted
score is determined for students from two midterm exam scores both weighted
at 30%, and a final exam score at 40%. A grade is assigned on the following basis:
Total weighted score
Grade
<60
F
>=60 and <70
D
>=70 and <80
C
>=80 and <90
B
>=90
A
For each student, the program is to output the student number, the total weighted
score and the grade assigned. It is also required to count the number of students
receiving each of the five grades. The input will be in the form of a record, each
consisting of student number, midterm test 1, midterm test 2 and final test mark.
The iteration is to be terminated by a suitable dummy record. The summary will
then be printed showing the distribution of the grades. Draw the JSP.
Case Study
MAIN-CTRL
INITIAL
1,2
BODY
END
WHILE C1
13,14
PROCESS
INPUT
RECORD
*
CALCULATION
ASSIGN
OUTPUT &
NEXT
RECORD
5
4
C2
11,12
3
C3
o
A
6
C4
o
B
o
C
7
C5
8
o
D
9
o
F
10
Function List
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11 :
12 :
13:
14 :
Initialise all variables, counters
Get first record
Input record
Total Weighted score = 30% x Midterm Test 1+ 30% x Midterm
Test 2 + 40% x Final Test
Assign grade
Increase Counter A by 1
Increase Counter B by 1
Increase Counter C by 1
Increase Counter D by 1
Increase Counter F by 1
Print Student Number, Weighted Score and Grade.
Get next record
Print Summary Record
End Program
Condition List
C1 : Not EOF
C2 : Total weighted score >= 90
C3 : Total weighted score >= 80
C4 : Total weighted score >= 70
C5 : Total weighted score >= 60
(Note to Lecturers: This is an easier solution as
compared to the study guide, but acceptable for
examination purposes.)