Presentation is loading. Please wait.

Presentation is loading. Please wait.

Problem Solving and Program Planning

Similar presentations


Presentation on theme: "Problem Solving and Program Planning"— Presentation transcript:

1 Problem Solving and Program Planning
ICS4U – Computer Science

2 Overview Problem Solving Planning Samples Practice Assignment
Problem Solving Model Planning Problem-Definition Table Input-Processing-Output Chart Pseudocode Flowcharting Samples Practice Assignment

3 Problem Solving

4 Solve the following problem:
A flower has been placed in a coloured box. Each box carries a statement. Of the three statements, at most, only one is true. Which box contains the flower? If you solve it, think about how you got to your solution. Will visit the solution at the end. RED The flower is in this box. YELLOW The flower is not in this box. GREEN The flower is not in the red box.

5 Problem Solving Model

6 Identify the problem What is the current situation/problem?
What is the problem to be solved?

7 Analyze the problem What do we know already about the situation/problem? What are our assumptions? What is the knowledge base of the person for whom we're trying to problem-solve? What can or do they understand? What don't we know yet about the whole situation/problem?

8 Brainstorm ideas List all possible ideas to solve the problem.
No value judgment is to be passed on any suggestions. The more ideas, the better.

9 Prioritize ideas Establish pros and cons of each suggestion in step 3.
Rank the suggested ideas from step 3 according to a set criteria.

10 List the steps to be taken following the chosen solution
What are the steps/instructions we should take according to the top solution ranked in step 4? Will these steps/instructions be understood according to the knowledge base established in step 2?

11 Evaluate/Test the Solution
Do we have the desired results after following the steps in 5? Does the solution satisfy the needs of the person with the problem? What are some of the areas that are not correct/satisfactory? (back to step1)

12 Planning

13 Problem-Definition Table
Known Facts User Requirements Necessary Processing What are some of the given facts? Do we need to gather more facts first? What does the user want done and what is the user required to do? What are the steps we have to take to produce user requirements?

14 Input-Processing-Output Chart
Input Data Processing Steps Output Data Fill this FIRST Fill this SECOND Fill this THIRD

15 Pseudocode Step-by-step English explanation of how to solve the problem.

16

17

18

19 Pseudocode for a Grading Program
If student's grade is greater than or equal to 50 Print "passed" else Print "failed"

20 Flowchart A diagram of the solution to the problem, using specific flowchart symbols.

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40 Samples

41 Sample #1 Let’s look at the original problem A flower has been placed in a coloured box. Each box carries a statement. Of the three statements, at most, only one is true. Which box contains the flower? If you solve it, think about how you got to your solution. RED The flower is in this box. YELLOW The flower is not in this box. GREEN The flower is not in the red box.

42 Known Facts User Requirements Necessary Processing
Problem-Definition Table Known Facts User Requirements Necessary Processing One box contains the flower Only 0 or 1 true statement exists Find the box that contains the flower Start from box 1 assuming it is true, and go through the statements in each box. Follow the true or false consequences of each statement to arrive at the solution

43 Input-Processing-Output Chart (next slide)

44 Input Data Processing Steps Output Data
Each statement inscribed on each box If red box is true, then yellow must also be true. However this is not possible because we would have two true statements and we are given that only one statement at most can be true. If red is false, i.e., the flower is not in the red box, then the statement on the green box is true If the green box’s statement is true, then the yellow box’s statement must be false because there can be at most only 1 true statement. Therefore, the flower is in the yellow box The Yellow Box contains the flower

45 Pseudocode 1. Read in the three boxes’ statements
2. Assume the red box statement is true 3. If (red box’s statement is true) then The yellow box’s statement is also true, and we have a contradiction with what we are given, i.e. only 1 statement at maximum is true, but now we would have two true statements if red box’s statement is true, so 4. If (red box’s statement is false) then The flower is not in the red box, i.e., green box’s statement is true And the yellow must be false because we are given that only 1 statement at maximum is true, so 5. If (yellow box’s statement is false) then the flower is in the yellow box.

46 Sample #2 Amy has a favourite colour in mind. Try guessing this colour. If you guess correctly, Amy lets you know that you are right and the program stops. Otherwise, the program keeps on asking you for a guess. However, if you give up, just type in ZZZ to stop.

47 Known Facts User Requirements Necessary Processing
Problem-Definition Table Known Facts User Requirements Necessary Processing There is one and only predetermined colour to guess The guess is typed in from the user If the guess is correct, a correct message is given and the program stops If the guess is wrong, the program keeps on asking for a guess until the guess is correct or the user types ZZZ Keep on guessing Amy’s favourite colour until the guess is correct or give up by typing ZZZ Assign a colour as Amy’s favourite colour Ask user to type in a guess While the guess is not equal to Amy’s colour and not equal to ZZZ, ask user to type in another guess If the guess is right, display a congratulations message End of program

48 Input Data Processing Steps Output Data
Input-Processing-Output Chart Input Data Processing Steps Output Data A guess typed in by the user Assign a colour as Amy’s favourite colour Ask user to type in a guess While the guess is not equal to Amy’s colour and not equal to ZZZ, ask user to type in another guess If the guess is right, display a congratulations message End of program A congratulations message if the guess is correct.

49


Download ppt "Problem Solving and Program Planning"

Similar presentations


Ads by Google