Flowchart
Flowchart
Do simple calculations like sum, percentage and average on the given data.
7. Flowchart
Tejas: We visited a computer exhibition for school students. We saw a super computer, demonstration of many uses of computer and many more interesting applications. Jyoti: In one of the stalls, we could enter any number as input and the computer was displaying the multiplication table of the number. (Shown above) This picture used by the person at the stall, to explain the sequence of steps followed by the computer, to display the table. Jyoti: We observed that those who did not know about computers and programming could also understand what was explained by the picture. Moz: This picture is a graphical representation called a flowchart. One of the main uses of a flowchart is to write the sequence of steps and logic of solving a problem, before writing the full computer program. It also helps in communicating the steps of the solution to others.
What is a flow chart? Concept
A flowchart is a graphical representation of the problem solving process. A flowchart gives a step-by-step procedure for solution of a problem.
90
Tejas: I see that various geometrical shapes are used in this representation. We are eager to learn about flowcharts. Moz: Let us start with a simple example. Look at the following flowchart of adding two natural numbers A and B. Let us discuss the problem solution and the geometrical shapes used.
Info
Start
Read A
Start
Read B
A= 845 B= 247
Sum= A+ B
Print Sum
End
Moz: What do you do when you are given a problem? Tejas: First we identify the goal. Here it is addition of tow given numbers. Moz: How do you achieve this goal? Jyoti: First we identify the data that is given. In this problem we have the two numbers A and B. Reading their values represented by parallelograms.
91
Moz: Right. What would you call this in computer terms? Jyoti: Input. Moz: The data or information that is available, (which is called input) is represented using a parallelogram in the flowchart. Moz: What is the next step? Tejas: The next step is to add the numbers, which is called processing in computers. We learned this term in Inside computer lesson. Moz: Correct. The details of processing of data is represented in a rectangle. Jyoti: The next step is to write the result of the addition which is output in computer terms. This is also specified in a parallelogram. Moz: Right. A parallelogram is used to specify both input and output in a flowchart. What else do you notice in the flowchart? Tejas: An arrow points from one step to the next step in the flowchart. Moz: In a flowchart arrows are used not only to connect the steps in a sequence but also to show a clear flow of the problem solving process. Jyoti: Start and also end of the flowchart are shown with an ellipse. Moz: A flowchart should give a clear indication as to where the problem solving flow starts and where it ends. The start of a problem solving process and the end are indicated using the ellipse. Jyoti: This is just like using step-wise thinking lesson step by step to solve a problem. Moz: Yes. The step by step method of solving the problem is specified using a flowchart. This helps you to be clear about the input, procedure and output. It also helps you to communicate the solution.
Concept Guidelines Uses of flowchart
To specify the method of solving a problem. To plan the sequence of a computer program. Communicate ideas, solutions.
Drawing of a flowchart
Follow step-by-step thinking and logical reasoning of solving a problem. Identify the goal or the solution to be found. Think of the sequence of steps for working out the solution to the problem. o Identify start, input, process, output and end. Use appropriate symbol to represent each step in the sequence. Use directional arrows to show the flow of the sequence of steps. Check that the flow of the solution is clearly communicated through the flowchart.
Moz: Now consider the following problem and draw the flowchart for its solution. Savani bought a toy for Rs. 325 and sold the same for Rs. 458. Explain how we can find if Savani has made a profit or a loss. Tejas: In this problem the goal is to find whether Savani makes a profit or loss. Jyoti: We know the Cost Price and the Selling Price. We can read them as input, so they are represented as parallelograms. Tejas: Next we have to compare Selling Price and Cost Price to find which price is more. This will tell us whether Savani has made profit or loss. How do we show comparison in a flowchart?
92
Moz: Can you phrase this step as a question with the two possible answers? Tejas: We can ask a question Is selling price more than cost price?. The answer to this question can be Yes or No. If, answer is Yes we have to calculate profit and if, answer is no we have to calculate loss. Moz: Right. In this step you have two alternate actions that can be taken. The decision of which action has to be taken is decided by the answer to the question. The answer can be Yes or No. This decision taking step is represented as follows in a flowchart.
Ouestiton? No
Yes
Jyoti: If the answer is Yes, it means that selling price is more than the cost price and Savani has made profit. Profit is calculated as, Selling price cost price If the answer is No it means that cost price is less than selling price and Savani has made loss. Loss is calculated as Cost price Selling price. Moz: Good. You have used logical reasoning to solve this problem. Now draw the flowchart. Flowchart - How to find profit or loss. For given example
Start
1. Read CP=325 SP= 458 2. Condition SP is grater than CP 3. Processing Profit= 458-325 = 133 4. Output Savani made profit of Rs. 133
Yes
Profit= SP-CP
Print Profit
Print Loss
Stop
93
Flowchart symbols and their purpose Geometric shape Ellipse Parallelogram Rectangle Diamond
No Yes
Purpose Start, End, Stop, Exit. (Stop or End or Exit these all mean End). Data, Input, output. Action, activity, process. Decision making step. Specify the question in the diamond. The next logical step is based on the answer Yes or No to the question. Arrows are used to connect the steps in a flowchart, to show the flow or sequence of the problem solving process.
Arrows
Moz: Suppose you have to write a scratch program for the above. Can you do it now? Tejas: Yes. We can! Jyoti: This is great. We can also plan a computer program using flowcharts. Jyoti: Sometimes we need to repeat a sequence. How do we represent this in the flowchart? Moz: Let us consider the multiplication table flowchart that you saw at the exhibition. See how repetition is represented in a flowchart. Flowchart of multiplication table for a given number N
Start
Multiplication table of 12 upto 10 Start N = 12 Count =1 12 * 1 = 12 Count = 1+1 = 2 12 * 2 = 24 Count = 2+1 = 3 Count = 9+1 = 10 12 * 10 = 120 Count =10 End
Count= 1 Arrow connects to the start of the sequence to be repeated Add 1 to the current value of count
Print N * Count
No
Is Count= 10
Yes
Stop
94
Tejas: The repetition sequence stops when count =10. So here a decision structure has been used to start and stop the repetition. Moz: Try out another problem to see how you can use such an assignment. Tejas: Let us draw a flowchart to find the factorial of a number. Moz: How do you find the factorial of a number? Jyoti: Suppose the number is 10. Then factorial of ten is calculated as 10! = 1*2*3*4*5*6*7*8*9*10 Moz: Good. Draw the flowchart. Find factorial of N
Start
Read N
Start N = 10 M=1 F=1 F = 1 * 1 = 1; M<10; M = 1 +1 = 2 F = 1 * 2 = 2; M<10; M = 2 +1 = 3 F = 2 * 3 = 6; M<10; M = 3 + 1= 4 F = 6 * 4 = 24;M<10; M = 4 +1 = 5 M<10; M = 9 + 1 = 10 F = 362880 * 10 = 3628800 M = N = 10 Factorial of 10 = 3628800 End
Set M= 1 Set F= 1
Is M=N?
Print Loss
End
95
Moz: Good. From the examples that you have seen, can you summarize what are all the basic structures of representation? Tejas: In the addition of numbers example, we saw how to show a sequence of processing steps. Jyoti: In the finding profit and loss example, we saw how alternate sequences can be specified using a decision box. Tejas: In the multiplication table and factorial examples, we saw how to show repetition of a sequence. Jyoti: Flowcharts can be drawn for a problem solving process using these three basic structures.
Sequence Sequence of steps are represented by symbols that follow each other top to bottom or left to right.
Selection A condition or a question is specified in the Decision box. Based on the evaluation of the condition one of the logical steps is taken next. The next logical step can be a process, decision, or end of the flowchart.
Ouestiton? No
Yes
Repetition Either the processing repeats or the control leaves the structure.
Ouestiton? Yes
Moz: Good. Now let us consider a game. Do you know the game of snakes and ladders? Tejas: Yes. Moz: Ok. Draw a flowchart to show how the game is played.
96
Yes
Yes
No
End
97
Tejas: The flowchart itself can be put into the box of the game so that those who want to play know the rules of the game and can easily understand how they win. Moz: We have seen some examples where flowcharts are used. There are many more uses of flowcharts and they can be used whenever you feel that you can communicate better with this graphical representation.
Other uses of flowchart
Classification of..... To teach and also to learn. Communicating ideas
Tejas: We are eager to learn another programming language. Moz: Sure. Next you will be learning BASIC where you can use some of the flowcharts that you have drawn in this lesson. Chin Chinaki...
Info
Outline
Main Points
Lesson Outcome
Presentation
Slides
Crea te
Impress
At the end of the lesson, you will be able to: Write an outline for a given topic. Enter content into the presentation application. Check content for consistency (font, grammar, spellings) and use design options. Follow guidelines for creating presentations.
98