Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

36
Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic CMPF144 Introduction to Problem Solving and Basic Computer Computer

Transcript of Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

Page 1: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

Chapter 3Planning Your Solution

CMPF144 Introduction to Problem Solving and Basic CMPF144 Introduction to Problem Solving and Basic ComputerComputer

Page 2: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

OverviewOverview Communicating with the Computer Organizing the Solution with Tools Testing the Solution Coding the Solution

2

Page 3: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

ObjectivesObjectives List and describe development tools Use problem analysis chart Use interactivity chart Use IPO chart Use algorithms (flowcharts and pseudocode) Describe importance of documentation

3

Page 4: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

Communicating with Communicating with ComputerComputer

We use programming language to communicate with a computer

Different type of programming language applies different syntax. SyntaxSyntax: the rules governing the computer operating

system, language and application Bug Bug : Coding error in a computer program DebuggingDebugging: Process to find and correct the coding errors

(bugs)

4

Page 5: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

Organizing Solution with Organizing Solution with ToolsTools

Four (4) categories of tools can be used to solve problems on a computer: Problem Analysis Chart (PAC) Interactivity Chart / Structure Chart IPO Chart Algorithm

Flowchart

pseudocode

5

Page 6: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

Problem Analysis Chart Problem Analysis Chart (PAC)(PAC) Shows a beginning analysis of the problem

Programmer will try to understand and analyze requirements of the problem

Allows programmer to glean only facts from the problem Separated into four (4) parts:

1. The given data

2. The required results

3. The processing that is required in the problem

4. A list of solution alternatives

6

Page 7: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

Basic Structure of Basic Structure of Problem Analysis ChartProblem Analysis Chart

7

Page 8: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

Problem Analysis Chart for Problem Analysis Chart for the Payroll Problemthe Payroll Problem

8

Page 9: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

Interactivity Chart / Interactivity Chart / Structure ChartStructure Chart Shows the overall layout or structure of the solution

Divide the processing identified into subtasks called modulesmodules these modules are connected together to show the interaction of

processing between modules Each module contain tasks for one function, not more than 20

instructions Example of function:

Enter data

Print result

calculate result

9

Page 10: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

Interactivity Chart (Cont.)Interactivity Chart (Cont.)

All modules are being controlled by a Control or Main Module

The breakdown (in the format of chart) allows programmer to view a complex problem in a few simpler parts.

10

Page 11: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

Example of Interactivity Example of Interactivity ChartChart

11

Do you know what are these Do you know what are these symbols???symbols???Triangle on upper left of box??Circle in chart??Diamond shape after Module2??

Page 12: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

Basic Interactivity Chart for Basic Interactivity Chart for the Payroll Problemthe Payroll Problem

The control module, read module, calculation module, and print module are BASIC to most programs.

From there, add other modules as needed along with the addition of processing symbols to show: Duplicates Decision Repetition in a loop

12

Page 13: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

Completed Interactivity Completed Interactivity Chart – The Payroll Chart – The Payroll

ProblemProblem

13

Page 14: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

Extends and organizes information in problem analysis chart (PAC)

Consists of four (4) main sections: Input Processing Module reference Output

14 IPO ChartIPO Chart

Page 15: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

IPO Chart (Cont.)IPO Chart (Cont.)

Shows more detail/information about: What data items are input?? What processing takes place on each specific data?? What information is output??

Sequence of completing IPO Chart:1.Output

2.Input

3.Processing

15

Is the sequence logical?? Why??

Page 16: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

IPO Chart for IPO Chart for the Payroll Problemthe Payroll Problem

16

Page 17: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

Shows the sequence of instructions, which will form solution

A good algorithm’s criteria: Instructions cannot assume anything Cannot skip steps Must be executable one step at a time Must be 100% complete

Two types of algorithm representation: Flowchart Pseudocode

17 AlgorithmAlgorithm

Page 18: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

18 FlowchartFlowchart

Graphical representation of algorithm, which shows the flow of the processing from the beginning to the end of a solution.

A flowchart always starts at the top of the page and flows to the bottom

There are flowchart symbols for use with various types of processing.

Page 19: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

Flowchart SymbolsFlowchart Symbols19

Page 20: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

Flowchart Symbols (Cont.)Flowchart Symbols (Cont.)20

Page 21: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

Flowchart - the Payroll ProblemFlowchart - the Payroll Problem21

Page 22: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

22Flowchart -Flowchart -

ReadRead Module in the Payroll Problem Module in the Payroll Problem

Page 23: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

23Flowchart – Flowchart –

Calc Calc Module in the Payroll ProblemModule in the Payroll Problem

Page 24: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

24Flowchart and Pseudocode for Flowchart and Pseudocode for

PrintPrint Module in the Payroll Problem Module in the Payroll Problem

Page 25: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

Overall Overall Flowchart - Flowchart - The Payroll The Payroll ProblemProblem

25

How to simplify this How to simplify this flowchart??flowchart??

Page 26: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

Algorithm which is represented in simple English form

Each instruction is written on a separate line Starts with “Start/Begin” and terminates with

“End” Keywords and instructions are written from top

to bottom, with only ONE entry and ONE exit. Groups of statements are formed into module,

and each module is given a specific name (however, this is optional).

26 PseudocodePseudocode

Page 27: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

Important keywords:

1. A computer can receive information Keyword: Read, Get

2. A computer can show information Keyword: Display, Print, Write

3. A computer can perform arithmetic calculation

27 Pseudocode (Cont.)Pseudocode (Cont.)

Page 28: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

4. A computer can assign value to memory location Keyword: Set, Initialize

5. A computer can compare two variables to decide which action to be taken Keyword; IF….ELSE…..END_IF

6. A computer can repeat a group of action. Keyword: WHILE…END_WHILE, REPEAT…..UNTIL

28 Pseudocode (Cont.)Pseudocode (Cont.)

Page 29: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

Overall Pseudocode – Overall Pseudocode – The Payroll ProblemThe Payroll Problem

Begin

REPEAT

Get Hours, PayRate

GrossPay = Hours * PayRate

Display GrossPay

UNTIL NoMoreEmployee = True

End

29

Page 30: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

Exercise (1)Exercise (1)

Try to organize solution for problem illustrated below, with the help of FOUR (4) tools that you have learnt in this chapter.

Build a program that read the value of the Build a program that read the value of the height, width and length of a box from height, width and length of a box from the user and print its volume.the user and print its volume.

30

Page 31: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

Exercise (2)Exercise (2)

Try to organize solution for problem in pp.76, PROBLEMS, Q6 with the help of FOUR (4) tools that you have learnt in this chapter.

31

Page 32: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

Consists of two main types: Internal documentation External documentation

32 DocumentationDocumentation

Page 33: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

For programmers Made up of remarks written with the

instructions to explain what is being done in the computer program, so that it can b easily understood by other programmers

Example: what is the main purpose of developing this program

What are the meaning of certain code blocks

Status of program development

??

33 Internal DocumentationInternal Documentation

Page 34: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

For end users Made up of manuals or help menus written

about the solutions. Example:

Tutorial which shows the steps to use program

Installation instruction

Help files

??

34 External DocumentationExternal Documentation

Page 35: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

to make sure that the solution meets requirements of user

to check for errors in logic or in setup of the expressions and equations.

programmer selects test data test data (a set of values for input data)and works them through every step in the solution. Example: to test expression X/Y

Test data for X and Y should be any numbers other than 1. WHY??

35 Testing the SolutionTesting the Solution

Page 36: Chapter 3 Planning Your Solution CMPF144 Introduction to Problem Solving and Basic Computer.

To be performed after the completion of analyzing problem and organizing the solution.

A process of converting algorithm into real program by using appropriate type of programming language

Python : to be covered in practical class

36 Coding the SolutionCoding the Solution