8/10/2019 Slide 07a - Control Structure_Selection
1/19
Computer Science Department FTSM
Control Structure:Selection(Part 1)
Knowledge:
Understand various concepts of selection control structure
Skill:
Be able to develop a program containing selection control structure
8/10/2019 Slide 07a - Control Structure_Selection
2/19
TK1913-C Programming 2
Selection Structure
Single
Selection
Double Selection
Multiple
Selection
8/10/2019 Slide 07a - Control Structure_Selection
3/19
TK1913-C Programming 3
Single SelectionPseudocode Structure
step a
if start
step m
step n
end_ifstep x
8/10/2019 Slide 07a - Control Structure_Selection
4/19
TK1913-C Programming 4
Single Selection
Step a
condition Step m
Step n
Step x
true
false
Step a
condition Step m
Step n
Step x
true
false
8/10/2019 Slide 07a - Control Structure_Selection
5/19
TK1913-C Programming 5
ExerciseDevelop an algorithm for the following problem:
A system to check/verify the eligibility of a person to voteduring 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 Youare eligible to vote and Your age is years oldmessages.
If the age is less than 20 years old, display Your age is years old message only.
8/10/2019 Slide 07a - Control Structure_Selection
6/19
TK1913-C Programming 6
Exercise - Answer
true
false
You are
eligible to vote
age
start
end
Your age is
years old
age > 20
true
false
You are
eligible to vote
age
start
end
Your age is
years old
age > 20
Assume the age is
12 years old
12 > 20 ?
FALSE !
Your age is 12 years
old
8/10/2019 Slide 07a - Control Structure_Selection
7/19
TK1913-C Programming 7
Something to ponder
the age is 37years old?What if ..
What about 20years old?
8/10/2019 Slide 07a - Control Structure_Selection
8/19
TK1913-C Programming 8
Lets recap Pseudocode Structure
step a
if start
step m
step n
end_ifstep x
Single Selection
Double selection has similar
structure except that
8/10/2019 Slide 07a - Control Structure_Selection
9/19
TK1913-C Programming 9
Double SelectionPseudocode Structure
step a
if startstep mstep n
end_if
else start
step xstep y
end_elsestep z
additional
steps at the
bottom
8/10/2019 Slide 07a - Control Structure_Selection
10/19
TK1913-C Programming 10
Double SelectionStep a
condition Step m
Step n
Step z
true
false
Step x
Step y
Step a
condition Step m
Step n
Step z
true
false
Step x
Step y
8/10/2019 Slide 07a - Control Structure_Selection
11/19
TK1913-C Programming 11
ExerciseDevelop an algorithm for the following problem:
A system to check/verify the eligibility of a person to voteduring 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 Youare eligible to vote and Your age is years oldmessages.
If the age is less than 20 years old, display You are noteligible to vote and Your age is years oldmessages.
8/10/2019 Slide 07a - Control Structure_Selection
12/19
TK1913-C Programming 12
Exercise - Answer
true
false
You are
eligible to vote
age
start
end
Your age is
years old
age > 20
Verify this
flowchart !
You are not
eligible to vote
8/10/2019 Slide 07a - Control Structure_Selection
13/19
TK1913-C Programming 13
Lets recap
Pseudocode Structure
step a
if start
step m
step n
end_ifstep x
Single SelectionPseudocode Structure
step a
if startstep mstep n
end_if
else start
step xstep yend_elsestep z
Double Selection
Guesshow does multiple
selection look like ?
8/10/2019 Slide 07a - Control Structure_Selection
14/19
TK1913-C Programming 14
Multiple Selection
Pseudocode Structure (Multi-way if)
step a
if startstep m
end_if
if start
step nend_if
step z
8/10/2019 Slide 07a - Control Structure_Selection
15/19
TK1913-C Programming 15
Multiple Selection
Step a
Condition1 Step m
Step n
Step z
true
false
Condition2
true
false
Step a
Condition1 Step m
Step n
Step z
true
false
Condition2
true
false
8/10/2019 Slide 07a - Control Structure_Selection
16/19
TK1913-C Programming 16
Multiple Selection
Pseudocode Structure (Cascaded if)
step a
if start
step mend_if
if startstep n
end_if
else startstep x
end_elsestep z
8/10/2019 Slide 07a - Control Structure_Selection
17/19
TK1913-C Programming 17
Multiple Selection
Step a
Condition1 Step m
Step n
Step z
true
false
Condition2true
false
Step x
Step a
Condition1 Step m
Step n
Step z
true
false
Condition2true
false
Step x
8/10/2019 Slide 07a - Control Structure_Selection
18/19
TK1913-C Programming 18
ExerciseDevelop a flowchart for the following problem.
Given a mark, determine its grade based on the
table below:
74 < mark < 100 grade = A64 < mark < 75 grade = B
54 < mark < 65 grade = C39 < mark < 55 grade = D0 < mark < 40 grade = E
others error message
8/10/2019 Slide 07a - Control Structure_Selection
19/19
TK1913-C Programming 19
End of Lecture 7 (Part 1)
Yes !! Thats all?Whats next???
PART 2on the way relax !