Topic 5 : SelectionSoftware Development Techniques
Selection 
•Selection let us provide branches of the flow of execution. 
•Only one kind of selection is discussed in this ...
The IfStructure•We have a formal syntax that we use for this in our pseudocode. if <condition> then// Statements to be exe...
Pseudocode to find a number is even or not.
Desk-Checking 
Line 
num 
remainder 
Input 
Output 
Remarks 
1 
0 
2 
0 
0 
3 
0 
0 
"Pleaseenter a number" 
Output 
4 
4 ...
Again Desk-Checking 
Line 
num 
remainder 
Input 
Output 
Remarks 
1 
0 
2 
0 
0 
3 
0 
0 
"Pleaseenter a number" 
Output ...
The IfStructure with otherwiseif <condition> then// Statements to be executed if condition is trueotherwise // Statements ...
Pseudocode to find a number is even or odd.
Desk-Checking 
Line 
num 
remainder 
Input 
Output 
Remarks 
1 
0 
2 
0 
0 
3 
0 
0 
"Pleaseenter a number" 
Output 
4 
9 ...
If Otherwise … Tasks1.A program takes whole number. Find whether it is greater than 100 or not. 2.A program takes input fr...
Multiple Courses of Action•we can provide for many courses of action by using otherwise ifif <condition 1> then// Statemen...
Is a number greater or less than or is 0
Now Desk-Checking 
Line 
num 
Input 
Output 
Remarks 
1 
0 
2 
0 
"Pleaseenter a number" 
Output 
3 
10 
10 
User enters 1...
Multiple Selection :: Tasks•Write pseudocode to find child, young, old or invalid input. •Display "Sunday" for 1, "Monday"...
Desk-Check Complexities•Good algorithms are succinct•succinct means "briefly and clearly expressed" •They should do what t...
Nesting•Selections within selection•Selections within loop•Selections within selection within selection within.....
Nested Selection•Write a pseudo to take age. If age is greater than 0, display “Valid age” otherwise display "Invalid age"...
Find child, young, old or invalid input
Compound Conditionals•Sometimes we have more than one condition. •Let us say we want a number between ten and twenty.
Compound Conditionals [Contd.] •This will work, but it is inappropriate•As far as possible, we want as few lines of code a...
Logical Operators1.OR2.AND3.NOT
Logical Operator -OR•If any condition or input is true, output will be trueTruth Table (A OR B) •A table used to outline a...
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 ...
Logical Operator -AND•If any condition or input is false, output will be falseTruth Table (A AND B) 
Condition1 (A) 
Condi...
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 
...
Logical Operator -NOT•If any condition or input is false, output will be true•If any condition or input is true, output wi...
Compound Conditionals -Previous Slide•Let us say we want a number between ten and twenty.
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 ...
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 ...
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 ...
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 ...
Any Questions??? End of Topic 5
Software Development Technique - Topic 05
Upcoming SlideShare
Loading in …5
×

Software Development Technique - Topic 05

2,167 views
2,038 views

Published on

Published in: Education, Technology, Spiritual
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,167
On SlideShare
0
From Embeds
0
Number of Embeds
1,255
Actions
Shares
0
Downloads
110
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Software Development Technique - Topic 05

  1. 1. Topic 5 : SelectionSoftware Development Techniques
  2. 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. 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. 4. Pseudocode to find a number is even or not.
  5. 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. 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. 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. 8. Pseudocode to find a number is even or odd.
  9. 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. 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. 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. 12. Is a number greater or less than or is 0
  13. 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. 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. 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. 16. Nesting•Selections within selection•Selections within loop•Selections within selection within selection within.....
  17. 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. 18. Find child, young, old or invalid input
  19. 19. Compound Conditionals•Sometimes we have more than one condition. •Let us say we want a number between ten and twenty.
  20. 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. 21. Logical Operators1.OR2.AND3.NOT
  22. 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. 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. 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. 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. 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. 27. Compound Conditionals -Previous Slide•Let us say we want a number between ten and twenty.
  28. 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. 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. 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. 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. 32. Any Questions??? End of Topic 5

×