Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Computer Science 9608 (Notes)

Chapter: 2.1 Algorithm design and problem-


solving

Topic: 2.1.2 Structure chart


Structure charts

A Structure Chart in software engineering is a chart which shows the breakdown of a system to its lowest
manageable parts. They are used in structured programming to arrange program modules into a tree.
Each module is represented by a box, which contains the module's name. The tree structure visualizes the
relationships between modules, showing data transfer between modules using arrows.

Page 1 of 8
Computer Science 9608 (Notes)
Chapter: 2.1 Algorithm design and problem-
solving

Topic: 2.1.2 Structure chart


Structured Charts are an example of a top-down design where a problem (the program) is broken into its 0T 0T 0T 0T

components.

Symbol Name Meaning

Module Each Box represents a programming module, this might be something that calculates the average of
Process
Name some figures, or prints out some pay slips

Data
Data being passed from module to module that needs to be processed.
Couple

[Extension - you don't need to know this for the exam] Check data sent to process to stop or start
Flag processes. For example when the End of a File that is being read is reached, or a flag to say whether
data sent was in the correct format

Let's take a look at a simple example of how this might be executed when representing the following code:
3T 3T 10T

Sub calculateAverage()
3T 3T 3T 3T4

Dim avg as integer


10T

inputNums()
47T 47T 10T 10T 10T

avg= average(num1, num2)


10T 10T 10T

outputAvg(avg)
3T

end sub
3T 3T 10T 10T 10T

function average(a,b)
3T 10T3 10T 47T 47T 10T 10T47 40T7

return(a + b)/2
3T

end function
3T 3T 10T

subinputNums()
3T 3T 3T 3T4

dim num1 asinteger


3T 3T 3T 3T4

dim num2 asinteger


47T 47T 47T 36T47 10T36

num1 = console.readline()
47T 47T 47T 36T47 10T36

num2 = console.readline()
3T

end sub
3T 3T 10T 10T 10T

suboutputAvg(x)
47T 36T47 10T36 10T45 45T7 47T 10T

console.writeline("average = "& x)
3T

end sub

Page 2 of 8
Computer Science 9608 (Notes)
Chapter: 2.1 Algorithm design and problem-
solving

Topic: 2.1.2 Structure chart

Exercise: Structure Charts

Create structure charts for the following code:


3T 3T 10T

sub main()
3T 3T 3T 3T4

dim num1 asinteger


3T 3T 3T 3T4

dim num2 asinteger


3T 3T 3T 3T4

dim avg as integer


10T

sayHello()
47T 40T7

num1 = 34
47T 40T7

num2 = 89
47T 47T 10T 10T 10T

avg= average(num1, num2)


3T

end sub
3T 3T 10T 10T 10T

function average(a,b)
3T 10T3 10T 47T 47T 10T 10T47 40T7

return(a + b)/2
3T

end function
3T 3T 10T

sub sayHello()
47T 36T47 10T36 10T45 10T45

console.writeline("hello")
3T

end sub

Page 3 of 8
Computer Science 9608 (Notes)
Chapter: 2.1 Algorithm design and problem-
solving

Topic: 2.1.2 Structure chart

Answer

A structure chart for the above code

Page 4 of 8
Computer Science 9608 (Notes)
Chapter: 2.1 Algorithm design and problem-
solving

Topic: 2.1.2 Structure chart

Selection

Structure Chart representation of the selection code

A selection in a Structure Chart is determined by the diamond symbol. This means a condition will be
checked and depending on the result, different modules will be executed.
3T 3T 10T

sub main()
3T 3T 3T 3T4

dim num1 as integer


47T 47T 47T 36T47 10T36

num1 = console.readline()
3T 3T 47T 40T7 3T40

if num1 = 7 then
10T

luckyNumber()
3T

else
10T

otherNumber()
3T

endif
3T

end sub

Page 5 of 8
Computer Science 9608 (Notes)
Chapter: 2.1 Algorithm design and problem-
solving

Topic: 2.1.2 Structure chart


Iteration

Structure Chart of the code below

Using the semicircular arrows, we can represent iteration in Structure Charts.

The arrow encompasses a link to a module, implying that module is executed multiple times. Let's take a
look at a coded example:
3T 3T 10T

sub main()
3T 3T 3T 3T4

dim num1 as integer


47T 47T 47T 36T47 10T36

num1 = console.readline()
3T 3T 47T 40T7 3T40

while num1 > 0 do


47T 47T 10T 10T 10T

num1 = countdown(num1)
3T

end while
3T

end sub
3T 3T 10T 10T 10T

sub countdown(a)
3T 3T 47T 40T7

return (a-1)
3T 3T

end sub

Page 6 of 8
Computer Science 9608 (Notes)
Chapter: 2.1 Algorithm design and problem-
solving

Topic: 2.1.2 Structure chart


Exercise: Structure Charts, Iteration and Selection

Create structure charts for the following code:


3T 3T 10T

Sub howManyThrees()
3T 3T 3T 3T4

dim num1, count, total as integer


47T 47T 10T

num1 = startMsg()
47T 40T7

count = 0
47T 40T7

total = 0
3T 3T 47T 40T7 3T40

while num1 > 0 do


10T 10T 10T

checkNumber(count, total, num1)


47T 47T 47T 40T7

num1 = num1 -1
3T

end while
10T 10T 10T

endMsg(count)
3T

end sub
3T 3T 10T 10T3 3T 3T 3T 3T 3T 10T

sub checkNumber(byRef c, byRef t, byVal n)


3T 3T 3T 3T40 40T7 40T7 3T40

If n MOD 3 = 0 Then
47T 47T 10T 10T 10T

c = divBy3(c)
3T

Else
47T 47T 10T 10T 10T

t = add(n, t)
3T

EndIf
3T

End sub
3T 3T 10T 10T 10T

function divBy3(x)
3T 3T 47T 40T7

return x +1
3T

end function
3T 3T 10T 10T 10T

function add(n, t)
3T 3T 47T 47T

return n + t
3T

end function
3T 3T 10T

function startMsg()
47T 36T47 10T36 10T45 10T45

console.writeline("program started, enter your number")


3T 3T 47T 36T47 10T36

return console.readline()
3T

end function
3T 3T 10T 10T 10T

sub endMsg(n)
47T 36T47 10T36 10T45 45T7 47T 10T

console.writeline("number of threes : "& n)


3T

end sub

Page 7 of 8
Computer Science 9608 (Notes)
Chapter: 2.1 Algorithm design and problem-
solving

Topic: 2.1.2 Structure chart

Answer :

Page 8 of 8

You might also like