Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Computer Fundamentals
Pradeep K. Sinha
Priti Sinha
Chapter 11
Planning the
Computer Program
Chapter 11: Planning the Computer Program Slide 1/50
Learning Objectives
1
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
Purpose of Program
Planning and Algorithm
Ref. Page 196 Chapter 11: Planning the Computer Program Slide 4/50
2
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
What is an Algorithm?
Algorithm refers to the logic of a program
It is a step-by-step description of how to arrive at a solution
to a given problem
Is defined as a sequence of instructions that when executed
in the specified sequence, the desired results are obtained
Instructions must possess following characteristics:
Each instruction should be precise and unambiguous
Each instruction should be executed in a finite time
No instruction should be repeated infinitely. This ensures that
the algorithm terminates ultimately
After executing the instructions (when the algorithm
terminates), the desired results are obtained
Ref. Page 197 Chapter 11: Planning the Computer Program Slide 5/50
Ref. Page 197 Chapter 11: Planning the Computer Program Slide 6/50
3
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
Step 8: Stop.
Ref. Page 197 Chapter 11: Planning the Computer Program Slide 7/50
Ref. Page 198 Chapter 11: Planning the Computer Program Slide 8/50
4
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
Ref. Page 198 Chapter 11: Planning the Computer Program Slide 9/50
Representation of Algorithms
As programs
As flowcharts
As pseudocodes
Ref. Page 198 Chapter 11: Planning the Computer Program Slide 10/50
5
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
Flowcharts
What is a Flowchart?
Flowchart is a pictorial representation of an algorithm
Programmers often use it as a program-planning tool
It uses boxes of different shapes to denote different types
of instructions
Process of drawing a flowchart for an algorithm is known as
flowcharting
Ref. Page 199 Chapter 11: Planning the Computer Program Slide 12/50
6
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
Ref. Page 199 Chapter 11: Planning the Computer Program Slide 13/50
Ref. Page 199 Chapter 11: Planning the Computer Program Slide 14/50
7
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
Ref. Page 200 Chapter 11: Planning the Computer Program Slide 15/50
Yes A=B
Ref. Page 201 Chapter 11: Planning the Computer Program Slide 16/50
8
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
I=?
=0 =1 =2 =3 =4 =5 = Other
Ref. Page 201 Chapter 11: Planning the Computer Program Slide 17/50
Ref. Page 201 Chapter 11: Planning the Computer Program Slide 18/50
9
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
Percentage = Total / 10
Stop
Ref. Page 202 Chapter 11: Planning the Computer Program Slide 19/50
Ref. Page 202 Chapter 11: Planning the Computer Program Slide 20/50
10
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
Ref. Page 203 Chapter 11: Planning the Computer Program Slide 21/50
Count = 0
Percentage = Total/10
Ref. Page 204 Chapter 11: Planning the Computer Program Slide 22/50
11
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
Yes
Is Rollno = 0000000?
Generalized flowchart
No for the solution of
Add marks of all subjects Example 4 using the
Stop
giving Total concept of trailer
record. Here the
process loop is
Percentage = Total / 10 terminated by detecting
a special non-data
record.
Write output data
Ref. Page 204 Chapter 11: Planning the Computer Program Slide 23/50
Ref. Page 204 Chapter 11: Planning the Computer Program Slide 24/50
12
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
Yes
Is Rollno = 9999999?
No Write Count
Add marks of all subjects giving Total Stop
Percentage = Total/10
No
Is Percentage = > 30?
Yes
Write output data
Add 1 to Count
Ref. Page 205 Chapter 11: Planning the Computer Program Slide 25/50
Ref. Page 208 Chapter 11: Planning the Computer Program Slide 26/50
13
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
Count = 0
Yes 2
Is Sexcode = Z?
No
1 No Is Sexcode = F?
Yes
Add marks of all subjects giving Total
Percentage = Total / 10
3
(Continued on next slide)
No
1 Is Percentage = > 45?
Yes
2
No
1 Is Percentage < 60?
Write Count
Yes
Write output data
Stop
Add 1 to Count
Ref. Page 208 Chapter 11: Planning the Computer Program Slide 28/50
14
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
Levels of Flowchart
Ref. Page 209 Chapter 11: Planning the Computer Program Slide 29/50
Part of a macro 1
flowchart
I=1 A micro
Total = 0 Flowchart
No
Is I > 10?
Yes
1
Ref. Page 209 Chapter 11: Planning the Computer Program Slide 30/50
15
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
Flowcharting Rules
First chart the main line of logic, then incorporate detail
Ref. Page 209 Chapter 11: Planning the Computer Program Slide 31/50
Flowcharting Rules
Ref. Page 209 Chapter 11: Planning the Computer Program Slide 32/50
16
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
Advantages of Flowcharts
Better communication
Flowchart is a pictorial representation of a program
Effective analysis
Macro flowchart, which charts the main line of logic of a
software system, becomes the systems model
Effective synthesis
Group of programmers are associated with the design of a big
software system
Each programmer is responsible for designing only a part of
the entire system
Flowcharts of all programmers put together can help visualize
the overall system design
Ref. Page 210 Chapter 11: Planning the Computer Program Slide 33/50
Advantages of Flowcharts
Proper program documentation
Documentation involves collecting, organizing, storing, and
maintaining a complete historical record of programs, and other
documents associated with a system
Flowcharts often provide valuable documentation support
Efficient coding
Once a flowchart is ready, programmers find it very easy to write
the corresponding program because the flowchart acts as a road
map
Systematic debugging
Flowchart is very helpful in detecting, locating, and removing
mistakes (bugs) in a program in a systematic manner
Systematic testing
Flowchart is very helpful in designing test data for systematic
testing of programs
Ref. Page 210 Chapter 11: Planning the Computer Program Slide 34/50
17
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
Limitations of Flowchart
Ref. Page 211 Chapter 11: Planning the Computer Program Slide 35/50
Pseudocode
18
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
What is Pseudocode?
Pseudocode is another program-planning tool used for
planning program logic
Pseudo means imitation or false and Code refers to the
instructions written in a programming language
Pseudocode is an imitation of actual computer instructions
Pseudo-instructions are phrases written in a natural language
Pseudocode uses a structure that resembles computer
instructions
A programmer can concentrate solely on developing the logic
of a program without worrying about the syntax
He/she can convert the pseudocode easily into a suitable
programming language
Ref. Page 211 Chapter 11: Planning the Computer Program Slide 37/50
1. Sequence logic,
2. Selection logic, and
3. Iteration (or looping) logic
Ref. Page 212 Chapter 11: Planning the Computer Program Slide 38/50
19
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
Sequence Logic
It is used for performing instructions one after another
in sequence.
Process 1
Process 1
Process 2
Process 2
Ref. Page 212 Chapter 11: Planning the Computer Program Slide 39/50
Selection Logic
Also known as decision logic, it is used for making
decisions
Ref. Page 213 Chapter 11: Planning the Computer Program Slide 40/50
20
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
Yes No IF Condition
IF (condition)
THEN Process 1
THEN ELSE ELSE Process 2
Process 1 Process 2
ENDIF
Ref. Page 213 Chapter 11: Planning the Computer Program Slide 41/50
Yes No
IF (condition)
IF Condition
THEN
THEN Process 1
Process 1
ENDIF
Ref. Page 213 Chapter 11: Planning the Computer Program Slide 42/50
21
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
Yes
Type 1 Process 1
No
Yes
Type 2 Process 2 CASE Type
Yes
Type n Process n
Case Type n: Process n
No
ENDCASE
(a) Flowchart
(b) Pseudocode
Ref. Page 214 Chapter 11: Planning the Computer Program Slide 43/50
1. DOWHILE
2. REPEATUNTIL
Ref. Page 214 Chapter 11: Planning the Computer Program Slide 44/50
22
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
Iteration (or Looping) Logic
(DOWHILE Structure)
False
Condition?
True
Process 1 DO WHILE Condition
Process 1
Block
Process n
Process n ENDDO
Ref. Page 215 Chapter 11: Planning the Computer Program Slide 45/50
Process 1
REPEAT
Process 1
Process n
Process n
False
Condition? UNTIL Condition
True
(a) Flowchart (b) Pseudocode
Ref. Page 215 Chapter 11: Planning the Computer Program Slide 46/50
23
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
Ref. Page 216 Chapter 11: Planning the Computer Program Slide 47/50
Advantages of Pseudocode
Converting a pseudocode to a programming language
is much more easier than converting a flowchart to a
programming language
Ref. Page 216 Chapter 11: Planning the Computer Program Slide 48/50
24
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
Limitations of Pseudocode
Ref. Page 217 Chapter 11: Planning the Computer Program Slide 49/50
Key Words/Phrases
Algorithm
Basic logic structures
Control structures
Flowchart
Iteration logic
Looping logic
Micro flowchart
Macro flowchart
Pseudocode
Program Design Language (PDL)
Sequence logic
Selection logic
Sentinel value
Structured programming
Trailer record
25