Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Like this presentation? Why not share!

2,167 views

2,038 views

2,038 views

Published on

No Downloads

Total views

2,167

On SlideShare

0

From Embeds

0

Number of Embeds

1,255

Shares

0

Downloads

110

Comments

0

Likes

5

No embeds

No notes for slide

- 1. Topic 5 : SelectionSoftware Development Techniques
- 2. Selection •Selection let us provide branches of the flow of execution. •Only one kind of selection is discussed in this topic, but some languages have several types. •We call it an Ifthen structure. •It can also have otherwiseparts
- 3. The IfStructure•We have a formal syntax that we use for this in our pseudocode. if <condition> then// Statements to be executed if condition is trueend if
- 4. Pseudocode to find a number is even or not.
- 5. Desk-Checking Line num remainder Input Output Remarks 1 0 2 0 0 3 0 0 "Pleaseenter a number" Output 4 4 0 4 User enters 4 5 4 0 4 % 2 = 0 6 4 0 If remainder is 0 then go to 7. Otherwise go to 8 7 4 0 "That's an even number!" 8 4 0 End of if 9 4 0 "Thanks for your input!"
- 6. Again Desk-Checking Line num remainder Input Output Remarks 1 0 2 0 0 3 0 0 "Pleaseenter a number" Output 4 7 0 7 User enters 7 5 7 1 7 % 2 = 1 6 7 1 If remainder is 0 then go to 7. Otherwise go to 8 8 7 1 End of if 9 7 1 "Thanks for your input!"
- 7. The IfStructure with otherwiseif <condition> then// Statements to be executed if condition is trueotherwise // Statements to be executed if condition is falseend if
- 8. Pseudocode to find a number is even or odd.
- 9. Desk-Checking Line num remainder Input Output Remarks 1 0 2 0 0 3 0 0 "Pleaseenter a number" Output 4 9 0 9 User enters 9 5 9 1 9 % 2 = 1 6 9 1 If remainder is 0 then go to 7. Otherwise go to 8 8 9 1 Otherwise –go to 9 9 9 1 "That's an odd number!" 10 9 1 End of if 11 9 1 "Thanks for your input!"
- 10. If Otherwise … Tasks1.A program takes whole number. Find whether it is greater than 100 or not. 2.A program takes input from user to find what day is today. If today is Saturday, display "It is a happy holiday." else "It is a Weekday". 3.Find whether user inputs positive or negative number. 4.WAP to take monthly salary. If yearly salary is above 200,000 then display “You have to pay tax” otherwise display “You don’t have to pay tax.”
- 11. Multiple Courses of Action•we can provide for many courses of action by using otherwise ifif <condition 1> then// Statements to be executed if condition 1 is trueotherwise if <condition 2> then// Statements to be executed if condition 2 is trueotherwise if <condition 3> then// Statements to be executed if condition 3 is trueotherwise // Statements to be executed if condition is falseend if
- 12. Is a number greater or less than or is 0
- 13. Now Desk-Checking Line num Input Output Remarks 1 0 2 0 "Pleaseenter a number" Output 3 10 10 User enters 10 4 10 If num (10) is less than 0 then go to 5. Otherwise, go to 6 6 10 If num (10) is 0 then go to 7. Otherwise go to 8. 8 10 Otherwise –go to 9 9 10 "It must be a positive number!" 10 10 End of if
- 14. Multiple Selection :: Tasks•Write pseudocode to find child, young, old or invalid input. •Display "Sunday" for 1, "Monday" for 2... "Saturday" for 7. •Convert single digit number to Word(Hint : 7 to Seven) •WAP to take monthly salary. Calculate the tax amount if yearly salary is . •1 to 200,000 tax is 1% •200,000 to 350,000 tax is 1% of first 200,000+15% of remaining salary•350,000 to abovetax is 1% of first 200,000 + 15% of next 150,000 + 25% of remaining salary
- 15. Desk-Check Complexities•Good algorithms are succinct•succinct means "briefly and clearly expressed" •They should do what they need to do in the minimum lines of code. •Before you begin a desk-check, see if your pseudocode is as succinct as it can be. •Simplify structures whenever you can.
- 16. Nesting•Selections within selection•Selections within loop•Selections within selection within selection within.....
- 17. Nested Selection•Write a pseudo to take age. If age is greater than 0, display “Valid age” otherwise display "Invalid age". Also if age is above 17, display “You are eligible to vote.” otherwise "You are not eligible to vote".
- 18. Find child, young, old or invalid input
- 19. Compound Conditionals•Sometimes we have more than one condition. •Let us say we want a number between ten and twenty.
- 20. Compound Conditionals [Contd.] •This will work, but it is inappropriate•As far as possible, we want as few lines of code as we can to achieve our goals. •We can however construct compound conditionals. •These are conditions with two or more parts, linked by a logical operator.
- 21. Logical Operators1.OR2.AND3.NOT
- 22. Logical Operator -OR•If any condition or input is true, output will be trueTruth Table (A OR B) •A table used to outline all the possible outcomes of a compound conditions is known as Truth Table. Condition1 (A) Condition2 (B) Output (X) False(0) False(0) False (0) False (0) True (1) True (1) True(1) False(0) True(1) True(1) True(1) True(1)
- 23. Logical Operator -ORTruth Table for 3 conditions (A OR B OR C) A B C X = A OR B OR C 0 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 1 1
- 24. Logical Operator -AND•If any condition or input is false, output will be falseTruth Table (A AND B) Condition1 (A) Condition2 (B) Output (X) False(0) False(0) False (0) False (0) True (1) False (0) True(1) False(0) False (0) True(1) True(1) True(1)
- 25. Logical Operator -ANDTruth Table for 3 conditions (A AND B AND C) A B C X = A AND B AND C 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 1
- 26. Logical Operator -NOT•If any condition or input is false, output will be true•If any condition or input is true, output will be falseTruth Table (NOT A) Condition1 (A) Output (X) False(0) True (1) True (1) False (0)
- 27. Compound Conditionals -Previous Slide•Let us say we want a number between ten and twenty.
- 28. Complete the Truth Table A B C A ANDB A OR C (AAND B) AND(AOR C) NOTB T T T T T F T F F T F F F T T F T F F F T F F F
- 29. Complete the Truth Table -Result A B C A ANDB A OR C (AAND B) AND (AOR C) NOTB T T T T T F T T F T T F T F F F T T T F F F T T F T T F T F F T F F F F F F T F T T F F F F F T
- 30. Complete the Truth Table -Result A B C A ANDB A OR C (AAND B) AND (AOR C) NOTB T T T T T T F T T F T T T F T F F F T F T T F F F T F T F T T F T F F F T F F F F F F F T F T F T F F F F F F T
- 31. Now Compute Following1.(A AND B) AND (A OR C) OR NOT B2.A OR B AND C3.A AND (B OR C) AND NOT B4.(NOT A) OR (NOT B) 5.(NOT A) AND (NOT B) Operator Precedence 1.NOT 2.AND 3.OR
- 32. Any Questions??? End of Topic 5

No public clipboards found for this slide

×
### Save the most important slides with Clipping

Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.

Be the first to comment