18
Flowcharting IT 12 | Fundamentals of Programming and Database Theory and Applications Ms. Jennifer O. Calleja | IT Instructor

Chapter 2 Representation Of Algorithms 2

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Chapter 2  Representation Of  Algorithms 2

FlowchartingIT 12 | Fundamentals of Programming and Database Theory and Applications

Ms. Jennifer O. Calleja | IT Instructor

Page 2: Chapter 2  Representation Of  Algorithms 2

Objectives

Upon completion of this chapter, you should be able to:

• Know the main steps for problem solving.

• Define term flowchart.• List and discus advantages and

disadvantages of flowchart as a logic development tool.

• Solve word problems using flowcharts.

Ms. Jennifer O. Calleja | IT Instructor

Page 3: Chapter 2  Representation Of  Algorithms 2

Steps in Problem solving

1. The first step in problem solving is to define the problem. The problem statement should be examined carefully to fully determine what question should be answered.

For example, consider this problem. A farmer had 100 chicken and all but 20 of them died. How many chicken does the farmer have left?

Ms. Jennifer O. Calleja | IT Instructor

Page 4: Chapter 2  Representation Of  Algorithms 2

Steps in Problem solving

2. After the problem is defined, the next step is to assemble all given data and to assign variable names to those quantities which are unknown. example:

Like the following statement: Let r = the radius of the circle

Ms. Jennifer O. Calleja | IT Instructor

Page 5: Chapter 2  Representation Of  Algorithms 2

Steps in Problem solving

3. Next, all unnecessary information should be discarded. Many problems contain information which has no meaning to the solution.

Consider this problem: A man received a check for 300 thousand pesos

of which he deposited 120 thousand pesos into his account. If his account balance was 200 thousand pesos after this deposit, how much was his balance before the deposit?

Ms. Jennifer O. Calleja | IT Instructor

Page 6: Chapter 2  Representation Of  Algorithms 2

Steps in Problem solving

•4. The next step is to discover relationships between the data express these relationships as equations.

Ms. Jennifer O. Calleja | IT Instructor

Page 7: Chapter 2  Representation Of  Algorithms 2

Steps in Problem solving

For example, read the radius of the circle from the keyboard then find its area and circumference.

Let R = the radius of the circleLet A = the area of the circleLet C = the circumference of the circleThus,A = π * r * rC = 2 * π * rRepresents the relationships in the problem

Ms. Jennifer O. Calleja | IT Instructor

Page 8: Chapter 2  Representation Of  Algorithms 2

Steps in Problem solving

5. The final step of problem solving is to arrange the equations into an algorithm. After the algorithm is established, the actual procedures may be executed by either the computer or manually.

Ms. Jennifer O. Calleja | IT Instructor

Page 9: Chapter 2  Representation Of  Algorithms 2

Flowchart

•a tool developed in the computer industry, for showing the steps involved in a process.

• A flowchart is a diagram made up of boxes, diamonds and other shapes, connected by arrows - each shape represents a step in the process, and the arrows show the order in which they occur.

Ms. Jennifer O. Calleja | IT Instructor

Page 10: Chapter 2  Representation Of  Algorithms 2

Flowcharting Symbols

Ms. Jennifer O. Calleja | IT Instructor

Process

Indicates any type of internal operation inside the

Processor or Memory

Input|output

Used for any Input / Output (I/O) operation. Indicates that the computer is to

obtain data or output results

Page 11: Chapter 2  Representation Of  Algorithms 2

Flowcharting Symbols

Ms. Jennifer O. Calleja | IT Instructor

Decision

Used to ask question that can be answered by True or

false | yes or no

connector

Allows the flowchart to be drawn without intersecting lines or without a reverse

flow

Page 12: Chapter 2  Representation Of  Algorithms 2

Flowcharting Symbols

Ms. Jennifer O. Calleja | IT Instructor

Terminal

Indicates the starting or ending of the program process or interrupt

program

Flow lines

Shows direction of flow

Page 13: Chapter 2  Representation Of  Algorithms 2

General Rules for Flowcharting

•The flowchart should be clear, neat and easy to follow.

•The usual direction of the flow of a procedure or a system is from left to right or top to bottom.

•Only one flow line should come out or from a process symbol.

Ms. Jennifer O. Calleja | IT Instructor

Page 14: Chapter 2  Representation Of  Algorithms 2

General Rules for Flowcharting

•Only one flow line should enter a decision symbol, but two or three flow lines, one for each possible answer, should leave the decision symbol.

•Only one flow line is used in conjunction with terminal symbol.

Ms. Jennifer O. Calleja | IT Instructor

Page 15: Chapter 2  Representation Of  Algorithms 2

General Rules for Flowcharting

•All boxes of the flowchart are connected with arrows

•Flowchart symbols have an entry point on the top of the symbol with no other entry points. The exit point for all flowchart symbols is on the bottom except for the DECISION SYMBOL.

•The Decision Symbol has two exit points; these can be on the sides or the bottom and one side.

Ms. Jennifer O. Calleja | IT Instructor

Page 16: Chapter 2  Representation Of  Algorithms 2

Advantages of Flowcharting•Good way of Communicating•Effective analysis•Proper documentation•Efficient coding•Proper debugging•Efficient program maintenance

Ms. Jennifer O. Calleja | IT Instructor

Page 17: Chapter 2  Representation Of  Algorithms 2

Draw a flowchart to find the sum of first 10 natural numbers.

This means that we want to find sum where sum is given by:Sum = 1 + 2 + 3 + ………………… 9 + 10.

Ms. Jennifer O. Calleja | IT Instructor

Page 18: Chapter 2  Representation Of  Algorithms 2

Pseudocode

•is one of the tools that can be used to write a preliminary plan that can be developed into a computer program

•a generic way of describing an algorithm without use of any specific programming language syntax.

Ms. Jennifer O. Calleja | IT Instructor