Download presentation
Presentation is loading. Please wait.
1
Flowcharts
2
Problem Solving using computers
Problem Solving using computers. Flowcharts: A language for expressing ‘Algorithms’
3
Flowcharts A pictorial representation of algorithms;
Flowcharts are not a programming language, rather it is an algorithm specification language; In an algorithm we specify the computation operations (arithmetic, logical, data input, data output) to be done, and their sequence; Each type of computation operation is denoted by a special symbol in the flowchart language; Symbols are connected by arrows to represent the order of the operations (sequence); Flowchart are useful during algorithm design; A flowchart can be relatively easily translated to a C++ program.
4
Flowcharts Symbols Calculation (square or rectangle)
You use it to specify a calculation, e.g. arithmetic expression. Examples: x = z+y; a = pi * r*r; z = z + 1 (add one to the current value of z and make that the new value of z); c = SQRT(x*x+y*y); x, z, y, a, c, pi, r are called variables. z = z +1 c = SQRT(x*x +y*y)
5
Flowcharts Symbols Data Input/Output (parallelogram)
Use it to specify an input or an output operation; By an input operation we mean a read operation of data from a peripheral device to Main Memory (e.g. user typing on a keyboard ); By an output operation we mean a write operation of data to a peripheral device from Main Memory (e.g. data displayed on the monitor, or sent to the printer); Examples: Read a value for the radius r from the keyboard; print value of the area a on the screen. input a print a
6
Flowcharts Symbols Decision or condition Testing (Diamond)
Use it to specify a condition to be tested. Based on the condition being true or false the next operation will be determined. Examples If (Adjusted Gross Income) > then taxRate = 0.31 else taxRate = 0.28 or if(r < 0 ) then print “invalid value for the radius” continue. no AGI>40000 ? TR = 0.28 yes TR = 0.31 You do it as an exercise
7
Flowcharts Symbols Decision or condition Testing cnt’d
A decision is composed of : A condition; An operation to be done if condition is true; An operation to be done if condition is false; We use decisions to enable repeating a set of operations multiple times; we call this construct a loop. An example of a loop is let sum = 0; do { input a; sum = sum+a; } until (a <0); sum = 0 input a sum = sum +a no a < 0 ? yes
8
Flowcharts Symbols Start/End
Every algorithm starts somewhere, and terminates somewhere; Every flowchart must have one start symbol and one or more end symbols; A start symbol denotes the start of the algorithm; When an end symbol is encountered this indicates the algorithm has terminated. start sum = 0 input a sum = sum +a a < 0 ? no yes print sum stop
9
Flowcharts Exercise Let’s Develop the flow chart for the algorithm that computes the circumference of a circle whose radius r is given as input. Don’t forget to check if the radius is positive number! Fig.2
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.