49
Problem Solving and Program Planning ICS4U – Computer Science

Problem Solving and Program Planning ICS4U – Computer Science

Embed Size (px)

Citation preview

Page 1: Problem Solving and Program Planning ICS4U – Computer Science

Problem Solving and Program Planning

ICS4U – Computer Science

Page 2: Problem Solving and Program Planning ICS4U – Computer Science

Overview

Problem SolvingProblem Solving Model

PlanningProblem-Definition TableInput-Processing-Output ChartPseudocodeFlowcharting

SamplesPracticeAssignment

Page 3: Problem Solving and Program Planning ICS4U – Computer Science

Problem Solving

Page 4: Problem Solving and Program Planning ICS4U – Computer Science

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.

REDThe flower is in

this box.

YELLOWThe flower is not

in this box.

GREENThe flower is not in the red box.

Page 5: Problem Solving and Program Planning ICS4U – Computer Science

Problem Solving Model

Page 6: Problem Solving and Program Planning ICS4U – Computer Science

Identify the problem

What is the current situation/problem?

What is the problem to be solved?

Page 7: Problem Solving and Program Planning ICS4U – Computer Science

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?

Page 8: Problem Solving and Program Planning ICS4U – Computer Science

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.

Page 9: Problem Solving and Program Planning ICS4U – Computer Science

Prioritize ideas

Establish pros and cons of each suggestion in step 3.

Rank the suggested ideas from step 3 according to a set criteria.

Page 10: Problem Solving and Program Planning ICS4U – Computer Science

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?

Page 11: Problem Solving and Program Planning ICS4U – Computer Science

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)

Page 12: Problem Solving and Program Planning ICS4U – Computer Science

Planning

Page 13: Problem Solving and Program Planning ICS4U – Computer Science

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?

Page 14: Problem Solving and Program Planning ICS4U – Computer Science

Input-Processing-Output Chart

Input Data Processing Steps

Output Data

Fill this FIRST Fill this SECOND Fill this THIRD

Page 15: Problem Solving and Program Planning ICS4U – Computer Science

Pseudocode

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

Page 16: Problem Solving and Program Planning ICS4U – Computer Science
Page 17: Problem Solving and Program Planning ICS4U – Computer Science
Page 18: Problem Solving and Program Planning ICS4U – Computer Science
Page 19: Problem Solving and Program Planning ICS4U – Computer Science

Pseudocode for a Grading Program

If student's grade is greater than or equal to 50 Print "passed" else Print "failed"

Page 20: Problem Solving and Program Planning ICS4U – Computer Science

Flowchart

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

Page 21: Problem Solving and Program Planning ICS4U – Computer Science
Page 22: Problem Solving and Program Planning ICS4U – Computer Science
Page 23: Problem Solving and Program Planning ICS4U – Computer Science
Page 24: Problem Solving and Program Planning ICS4U – Computer Science
Page 25: Problem Solving and Program Planning ICS4U – Computer Science
Page 26: Problem Solving and Program Planning ICS4U – Computer Science
Page 27: Problem Solving and Program Planning ICS4U – Computer Science
Page 28: Problem Solving and Program Planning ICS4U – Computer Science
Page 29: Problem Solving and Program Planning ICS4U – Computer Science
Page 30: Problem Solving and Program Planning ICS4U – Computer Science
Page 31: Problem Solving and Program Planning ICS4U – Computer Science
Page 32: Problem Solving and Program Planning ICS4U – Computer Science
Page 33: Problem Solving and Program Planning ICS4U – Computer Science
Page 34: Problem Solving and Program Planning ICS4U – Computer Science
Page 35: Problem Solving and Program Planning ICS4U – Computer Science
Page 36: Problem Solving and Program Planning ICS4U – Computer Science
Page 37: Problem Solving and Program Planning ICS4U – Computer Science
Page 38: Problem Solving and Program Planning ICS4U – Computer Science
Page 39: Problem Solving and Program Planning ICS4U – Computer Science
Page 40: Problem Solving and Program Planning ICS4U – Computer Science

Samples

Page 41: Problem Solving and Program Planning ICS4U – Computer Science

Sample #1

Let’s look at the original problemA 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.

REDThe flower is in

this box.

YELLOWThe flower is not

in this box.

GREENThe flower is not in the red box.

Page 42: Problem Solving and Program Planning ICS4U – Computer Science

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

Page 43: Problem Solving and Program Planning ICS4U – Computer Science

Input-Processing-Output Chart (next slide)

Page 44: Problem Solving and Program Planning ICS4U – Computer Science

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

Page 45: Problem Solving and Program Planning ICS4U – Computer Science

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.

Page 46: Problem Solving and Program Planning ICS4U – Computer Science

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.

Page 47: Problem Solving and Program Planning ICS4U – Computer Science

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

Page 48: Problem Solving and Program Planning ICS4U – Computer Science

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.

Page 49: Problem Solving and Program Planning ICS4U – Computer Science