Vous êtes sur la page 1sur 14

A/L ICT 2012/ 2013 Notes

7. Computer Programming
7.3 Flow Charts
A flowchart is a diagram to represents an algorithm or process.
Shows the process steps as various boxes connected with arrows.
A diagram that represents step-by-step solution to a problem.
Arrows represent flow of control.
Help analyzing, designing, documenting of programs

Flow Chart Symbols

Niranjan Meegammana
0777 606 796

www.shilpasayura.org
1

A/L ICT 2012/ 2013 Notes

Niranjan Meegammana
0777 606 796

www.shilpasayura.org
2

A/L ICT 2012/ 2013 Notes


Driving across town to reach a specific goal using a flowchart

Computer Troubleshooting FlowChart

Niranjan Meegammana
0777 606 796

www.shilpasayura.org
3

A/L ICT 2012/ 2013 Notes

Programming Flow Charts


Explain this flowchart

What would be the output?


Draw a flowchart to find the largest of three numbers A,B, and C.

Niranjan Meegammana
0777 606 796

www.shilpasayura.org
4

A/L ICT 2012/ 2013 Notes


Draw a flowchart for computing factorial N (N!)
Where N! = 1 2 3 N .

Practice Flow Charts


Draw a flowchart to read a number N and print all its
divisors.
Draw a flowchart for computing the sum of the digits of
any given number
Draw a flowchart to find the sum of given N numbers.
Draw a flowchart to computer the sum of squares of
integers from 1 to 50
Draw a flowchart to arrange the given data in an ascending
order.

Niranjan Meegammana
0777 606 796

www.shilpasayura.org
5

A/L ICT 2012/ 2013 Notes


Exercise 1
Nishan sells pumpkin at the market One day his wife wanted to
know at any time during the day:
How many sales have been sold?
What was the value of the biggest sale?
What was the value of the smallest sale?
What was the average value of sales?
Processes:
Maintain a counter of sales
Store the value of the most expensive sale
Store the value of the least expensive sale
Maintain total sales
Calculate Average

Variables :
Bunches_Sold
Highest_Price
Lowest_Price
Total_value
Average_Price

Decisions:
Find_Highest Value
Find_Lowest Value

Loops:
Selling Pumpkin

algorithm in step form


price of cheapest sale=0
price of highest sale=0
sales_made=0
While there are Pumpkins to sell
make a sell of Pumpkin
input current sale
total_sales=total_sales+current sale
increment the sales_made by 1
if price of current sale > price of highest sale
price of highest sale = price of current sale
end if
if price of current sale < price of cheapest sale
price of cheapest sale = price of current sale
end if
average_sale=total_sales/sales_made
print sales_made
print price of highest sale
print price of cheapest sale
print average_sale
end of while
Niranjan Meegammana
0777 606 796

www.shilpasayura.org
6

A/L ICT 2012/ 2013 Notes


Compare your Flowchart with following Flow Chart

Using nested loops in flow charts

Niranjan Meegammana
0777 606 796

www.shilpasayura.org
7

A/L ICT 2012/ 2013 Notes


Multiway selection in flow charts

Exercise
Assume you have the following data stored in a file
CLASS12A,Nishan,Ishan,Rishan,Sohan,Dashan,Kushan,Deshan,Ush
an,Ashan,CLASS12B,Milan,Dilan,Zilan,Rushan,CLASS12C,END
It represents students in different classes.
Design a program using flow charts to:
reads the data and displays the names of the students
under each class
count the number of students in each class
count the number of classes

Niranjan Meegammana
0777 606 796

www.shilpasayura.org
8

A/L ICT 2012/ 2013 Notes

Niranjan Meegammana
0777 606 796

www.shilpasayura.org
9

A/L ICT 2012/ 2013 Notes


Write Psuedocode for Flow Charts

Niranjan Meegammana
0777 606 796

www.shilpasayura.org
10

A/L ICT 2012/ 2013 Notes

Niranjan Meegammana
0777 606 796

www.shilpasayura.org
11

A/L ICT 2012/ 2013 Notes

Nassi-Schneiderman diagram
The Nassi-Schneiderman (NS) diagram is a graphical method of
stating algorithms. It is very easy to read for beginners.
NS diagram indicates an algorithm with a
process (Process 1) followed by a decision.
Each outcome of the decision has a process
associated with it. If the decision
evaluates as true then Proc 2 is carried
out, if false then Proc 3 is carried out. I

The process symbol

The decision symbol


The repeat condition extends to
the processes it controls

While construct is the reverse of


the repeat.

Niranjan Meegammana
0777 606 796

www.shilpasayura.org
12

A/L ICT 2012/ 2013 Notes

Comparison of NS diagram with flow charts

Compare and Contrast the advantages and disadvantages


Psuedocoding, Flowcharts and NS diagrams for program
designing.
Design a high level program to control a toy robot with sleep,
awake, walk, jump, rotate, crawl, run, climb functions.
Draw a flowchart for your program design.

Niranjan Meegammana
0777 606 796

www.shilpasayura.org
13

A/L ICT 2012/ 2013 Notes

Niranjan Meegammana
0777 606 796

www.shilpasayura.org
14

Vous aimerez peut-être aussi