Lecture 2
Lecture 2
1
Steps in using a computer as
problem solving tool
1. Develop an Algorithm and a Flowchart.
2. Write the program in programming language
(C, C++, JAVA, COBOL, etc.).
3. Enter the program in computer.
4. Test and Debug the program.
5. Run the program, input data, and get the
result from the computer.
2
What is ALGORITHM?
• Definition: Algorithm is a step by step
procedure to solve a problem (Finite steps).
3
The Flowchart
• Definition: A graphical representation of the
sequence of operations in an information
system or program.
– Information system flowcharts show how data
flows from source documents through the
computer to final distribution to users.
– Program flowcharts show the sequence of
instructions in a single program or subroutine.
Different symbols are used to draw each type of
flowchart.
4
The Flowchart
A Flowchart
– shows logic of an algorithm
– emphasizes individual steps and their
interconnections
– e.g. control flow from one action to the next
5
Symbols used in Flowcharts
Terminal Symbol:
indicates the starting or stopping point in the logic.
Input/Output Symbol:
Represents an input or output process in an algorithm
Process Symbol:
Represents any single process in an algorithm
Decision Symbol:
Represents a decision in the logic involving the
comparison of two values.
6
Cont…
Flow Lines
The arrow indicates the "direction" of flow.
Annotation Symbol
You can use it to write a note/comment.
In-Page Connector
It is used to join two parts of program on same page.
Also used for goto or jump to some specific point.
Off-Page Connector
Used to connect two parts of flowchart which are on
different pages.
7
The three basic control structures:-
1. Sequence
2. Selection
3. Repetition
8
1. Sequence
Statemement a
Statemement b
Statemement c
9
Example
Problem : Write an algorithm and draw a flowchart for a
program to find the area of a rectangle.
START
Algorithm
Input W, L
• Step 1: Input W, L
• Step 2: A L x W ALxW
• Step 3: Print A
Print A
STOP
10
2. Selection
T F
F Condition p?
Condition p?
T
Statemement a Statemement b
Statemement a
11
Example
Problem : Write an algorithm and draw a flowchart for a program
to find overall grade in four courses, i.e., FAIL if average is less
than 50, PASS otherwise.
START
Input
Algorithm: M1,M2,M3,M4
STOP
12
3. Repetition
F
Condition p?
Statemement block
13
Example
Problem : Write an algorithm and draw a flowchart for steps in
SDLC (Software Development Life Cycle)
Algorithm Flowchart
1. Start
5. If error
If error in Design
Else
6. Stop 14
More examples
• More examples can be found in Lab 1 Material
15