Download presentation
Presentation is loading. Please wait.
Published byWilfred Cameron Modified over 9 years ago
1
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
2
TK1913-C Programming2 TK1913-C Programming 2 Selection Structure Single Selection Double Selection Multiple Selection
3
TK1913-C Programming3 TK1913-C Programming 3 Single Selection Pseudocode Structure step a if start step m step n end_if step x Pseudocode Structure step a if start step m step n end_if step x
4
TK1913-C Programming4 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
5
TK1913-C Programming5 TK1913-C Programming 5 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 person’s age. If the age is greater than 20 years old, then display “You are eligible to vote” and “Your age is years old” messages. If the age is less than 20 years old, display “Your age is years old” message only.
6
TK1913-C Programming6 TK1913-C Programming 6 Exercise - Answer true false “You are eligible to vote” agestartend “Your age is years old” age > 20 truefalse “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
7
TK1913-C Programming7 TK1913-C Programming 7 Something to ponder … the age is 37 years old? What if ….. What about 20 years old?
8
TK1913-C Programming8 TK1913-C Programming 8 Let’s recap … Pseudocode Structure step a if start step m step n end_if step x Pseudocode Structure step a if start step m step n end_if step x Single Selection Double selection has similar structure except that …
9
TK1913-C Programming9 TK1913-C Programming 9 Double Selection Pseudocode Structure step a if start step m step n end_if else start step x step y end_else step z Pseudocode Structure step a if start step m step n end_if else start step x step y end_else step z … additional steps at the bottom …
10
TK1913-C Programming10 TK1913-C Programming 10 Double Selection Step 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
11
TK1913-C Programming11 TK1913-C Programming 11 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 person’s age. If the age is greater than 20 years old, then display “You are eligible to vote” and “Your age is years old” messages. If the age is less than 20 years old, display “You are not eligible to vote” and “Your age is years old” messages.
12
TK1913-C Programming12 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”
13
TK1913-C Programming13 TK1913-C Programming 13 Let’s recap … Pseudocode Structure step a if start step m step n end_if step x Pseudocode Structure step a if start step m step n end_if step x Single Selection Pseudocode Structure step a if start step m step n end_if else start step x step y end_else step z Pseudocode Structure step a if start step m step n end_if else start step x step y end_else step z Double Selection Guess…how does multiple selection look like ?
14
TK1913-C Programming14 TK1913-C Programming 14 Multiple Selection Pseudocode Structure (Multi-way if) step a if start step m end_if if start step n end_if step z Pseudocode Structure (Multi-way if) step a if start step m end_if if start step n end_if step z
15
TK1913-C Programming15 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
16
TK1913-C Programming16 TK1913-C Programming 16 Multiple Selection Pseudocode Structure (Cascaded if) step a if start step m end_if if start step n end_if else start step x end_else step z Pseudocode Structure (Cascaded if) step a if start step m end_if if start step n end_if else start step x end_else step z
17
TK1913-C Programming17 TK1913-C Programming 17 Multiple Selection Step a Condition1 Step m Step n Step z true false Condition2 true false Step x Step a Condition1 Step m Step n Step z true false Condition2 true false Step x
18
TK1913-C Programming18 TK1913-C Programming 18 Exercise Develop a flowchart for the following problem. Given a mark, determine its grade based on the table below: 74 < mark < 100grade = A 64 < mark < 75grade = B 54 < mark < 65grade = C 39 < mark < 55grade = D 0 < mark < 40grade = E others error message
19
TK1913-C Programming19 TK1913-C Programming 19 End of Lecture 7 (Part 1) Yes !! That’s all? What’s next??? PART 2 on the way… relax !
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.