# Computer Science Department FTSM Control Structure: Selection (Part 1) Knowledge: Understand various concepts of selection control structure Skill: Be.

## Presentation on theme: "Computer Science Department FTSM Control Structure: Selection (Part 1) Knowledge: Understand various concepts of selection control structure Skill: Be."— Presentation transcript:

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

TK1913-C Programming2 TK1913-C Programming 2 Selection Structure Single Selection Double Selection Multiple Selection

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

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

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.

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

TK1913-C Programming7 TK1913-C Programming 7 Something to ponder … the age is 37 years old? What if ….. What about 20 years old?

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 …

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 …

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

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.

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”

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 ?

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

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

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

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

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

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 !

Download ppt "Computer Science Department FTSM Control Structure: Selection (Part 1) Knowledge: Understand various concepts of selection control structure Skill: Be."

Similar presentations