1 / 19

Control Structure: Selection (Part 1)

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. Single Selection. Multiple Selection. Double Selection. Selection Structure. Single Selection.

Download Presentation

Control Structure: Selection (Part 1)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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 Computer Science Department

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

  3. Single Selection • Pseudocode Structure • step a • if <condition is true> start • step m • step n • end_if • step x TK1913-C Programming3

  4. Step a true condition Step m Step n false Step x Single Selection Step a true condition Step m Step n false Step x TK1913-C Programming4

  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 <age> years old” messages. If the age is less than 20 years old, display “Your age is <age> years old” message only. TK1913-C Programming5

  6. start age “You are eligible to vote” true age > 20 FALSE ! false false “Your age is <age> years old” end Exercise - Answer start Assume the age is 12 years old age true “You are eligible to vote” 12 > 20 ? age > 20 “Your age is <age> years old” Your age is 12 years old end TK1913-C Programming6

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

  8. Single Selection • Pseudocode Structure • step a • if <condition is true> start • step m • step n • end_if • step x Let’s recap … Double selection has similar structure except that … TK1913-C Programming8

  9. … additional steps at the bottom … 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 Programming9

  10. Step a condition true Step m false Step n Step x Step y Step z Double Selection Step a condition true Step m false Step n Step x Step y Step z TK1913-C Programming10

  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 <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 Programming11

  12. start age “You are eligible to vote” “You are not eligible to vote” age > 20 “Your age is <age> years old” end Exercise - Answer Verify this flowchart ! true false TK1913-C Programming12

  13. Double Selection Single 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 • Pseudocode Structure • step a • if <condition is true> start • step m • step n • end_if • step x Let’s recap … Guess…how does multiple selection look like ? TK1913-C Programming13

  14. 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 Programming14

  15. Step a Condition1 true Step m false Condition2 true Step n false Step z Multiple Selection Step a Condition1 true Step m false Condition2 true Step n false Step z TK1913-C Programming15

  16. 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 Programming16

  17. Step a Condition1 true Step m false true Condition2 Step n false Step x Step z Multiple Selection Step a Condition1 true Step m false true Condition2 Step n false Step x Step z TK1913-C Programming17

  18. Exercise Develop a flowchart for the following problem. Given a mark, determine its grade based on the table below: 74 < mark < 100 grade = A 64 < mark < 75 grade = B 54 < mark < 65 grade = C 39 < mark < 55 grade = D 0 < mark < 40 grade = E others error message TK1913-C Programming18

  19. Yes !! That’s all? What’s next??? PART 2 on the way… relax ! End of Lecture 7 (Part 1) TK1913-C Programming19

More Related