Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Selection
(Part 1)
Knowledge:
Understand various concepts of selection control structure
Skill:
Be able to develop a program containing selection control structure
FTSM
Selection Structure
Single
Selection
Multiple
Selection
Double Selection
TK1913-C Programming
Single Selection
Pseudocode Structure
step a
if <condition is true> start
step m
step n
end_if
step x
TK1913-C Programming
Single Selection
Step a
true
condition
Step m
false
Step n
Step x
TK1913-C Programming
Exercise
Develop an algorithm for the following problem:
A system to check/verify the eligibility of a person to vote
during the election is going to be developed. The input for
the system is the persons age.
If the age is greater than 20 years old, then display You
are eligible to vote and Your age is <age> years old
messages.
Exercise - Answer
start
Assume the age is
12 years old
age
true
12 > 20 ?
FALSE !
age > 20
You are
eligible to vote
false
Something to ponder
What if ..
the age is 37 years old?
Lets recap
Pseudocode Structure
Single Selection
step a
if <condition is true> start
step m
step n
end_if
step x
Double selection has similar
structure except that
TK1913-C Programming
Double Selection
Pseudocode Structure
step a
if <condition is true> start
step m
step n
end_if
else start
step x
step y
end_else
step z
TK1913-C Programming
additional
steps at the
bottom
9
Double Selection
Step a
condition
false
Step x
true
Step m
Step n
Step y
Step z
TK1913-C Programming
10
Exercise
Develop an algorithm for the following problem:
A system to check/verify the eligibility of a person to vote
during the election is going to be developed. The input for
the system is the persons age.
If the age is greater than 20 years old, then display You
are eligible to vote and Your age is <age> years old
messages.
If the age is less than 20 years old, display You are not
eligible to vote and Your age is <age> years old
messages.
TK1913-C Programming
11
Exercise - Answer
start
Verify this
flowchart !
age
true
age > 20
You are
eligible to vote
false
You are not
eligible to vote
Your age is <age>
years old
end
TK1913-C Programming
12
Lets recap
Pseudocode Structure
Pseudocode Structure
Double Selection
Single Selection
step a
step
a
if <condition
is true> start
step m is true> start
if <condition
step n
end_if step m
step n
else start
end_ifstep x
step y
step
x
end_else
Guesshow does multiple
step z
TK1913-C Programming
13
Multiple Selection
Pseudocode Structure (Multi-way if)
step a
if <condition_1 is true> start
step m
end_if
if <condition_2 is true> start
step n
end_if
step z
TK1913-C Programming
14
Multiple Selection
Step a
Condition1
true
Step m
false
true
Condition2
Step n
false
Step z
TK1913-C Programming
15
Multiple Selection
Pseudocode Structure (Cascaded if)
step a
if <condition_1 is true> start
step m
end_if
if <condition_2 is true> start
step n
end_if
else start
step x
end_else
step z
TK1913-C Programming
16
Multiple Selection
Step a
Condition1
true
Step m
false
true
Condition2
Step n
false
Step x
Step z
TK1913-C Programming
17
Exercise
Develop a flowchart for the following problem.
Given a mark, determine its grade based on the
table below:
74 < mark < 100
64 < mark < 75
54 < mark < 65
39 < mark < 55
0 < mark < 40
others
TK1913-C Programming
grade = A
grade = B
grade = C
grade = D
grade = E
error message
18
TK1913-C Programming
19