Wednesday, November 13, 2013

1.1.0 Flow charts


A flow chart presents a visual map of a program. The flowchart uses arrows to represent the direction of the program flow and boxes and other shapes to display actions. Note that in this discussion we are talking about a logic flow chart, a flow chart that represents the flow of logic in a program. Logic flowchart is different from a systems flow chart, which shows the flow of data through an entire computer system. Following example shows the symbols and shows how you might flowchart a program to find the sum of all the numbers between 1 and 100. There are a number of things to observe about this flowchart.

First, the program uses two places in the computer's memory as strange locations or places to keep intermediate results. In one location is a counter, which might be like a car speedometer: every time a mile passes, the counter counts it as a 1. In the other location the computer stores a sum that is a running total of the numbers counted. The sum location will eventually contain the sum of all numbers from 1 through 100: 1 + 2 + 3 + 4 + 5 + ... + 100.

Second, as we start the program, we must initialize the counter and the sum. When you initialize you set the staring values of certain storage locations, usually as the program execution begins. We will initialize the sum to 0 and the counter to 1.

Third, note the looping. You add the counter to the sum and a 1 to the counter and then you come to the decision diamond, which asks if the counter is greater than 100. If the answer is no, the computer loops back around and repeats the process. The decision box contains a comparison operation; the computer compares two numbers and perform alternative operations based on the comparison. If the result of the comparison is yes, the computer produces the sum as input, as indicated by the print instruction.

A loop is called an iteration-is the heart of computer programming. The beauty of the loop, which may be defined as repletion of instructions under the certain conditions, is that you, the programmer, have to describe certain instructions only once rather than describing them repeatedly. Once you have established the loop pattern and the condition for concluding (exiting from) the loop, the computer continues looping and exits as it has been instructed to do. The loop is considered a powerful programming tool because the code is reusable; once written. It can be called upon many times. Notice also that the flowchart can be modified easily to sum the numbers from 1 through 1000 or 5000 through 700 or some other variation


Flow chart Symbols




Example




































 














 

No comments:

Post a Comment