0% found this document useful (0 votes)
5 views

03-Principle of Programming

Uploaded by

peterthefroog
Copyright
© © All Rights Reserved
Available Formats
Download as PPSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

03-Principle of Programming

Uploaded by

peterthefroog
Copyright
© © All Rights Reserved
Available Formats
Download as PPSX, PDF, TXT or read online on Scribd
You are on page 1/ 31

Di P

r1 rivat
_
Fil Cha e Su
e1
. ng b
Di path e()
r1
En .pa =
Dr d S th

Chapter 3
ive Priv ub
1_ ate
Di Cha Su
Dr r1.p nge b
i ve a t ( )
1 h
En .Driv =

Principles of
dS e
ub
Pr
iv
Fil Form ate
e1
.Pa _Lo Sub
tte ad(
"*. rn =
En j p
d S g"
)
Programming &
ub

Problem Solving
Prepared By TCA Gafoor, AKM HSS Kottoor,Malappuram

http://www.hsslive.in
Program, Programming,
Programmer, Programming
Language
A computer program is a sequence of
instructions to solve a particular task.

Developing a program is called


programming.

A person who writes a program is called


programmer.

The language with rules, syntax etc used to


write a program is called programming
9847995577
Approaches in Problem Solving
Top down Design
Bottom up Design

9847995577
Top down design
Any complex problem can be solved by
breaking it down into different task and
solving each task. This concept is known top
down design
Top down–Breaking the overall procedure in to
modules and sub divide them until lowest level
reached.
Bottom up design
Bottom up- Starts from lowest level to the
highest level..
9847995577
Main Program

Sub Program
Sub Program 1 Sub Program 3
2

9847995577
Phases in Programming
Problem
Identification 1. Problem Identification
2. Algorithm & Flow Chart
Algorithm &
Flow Chart 3.Coding
4.Translation
Coding 5.Debugging
6.Execution & Testing
7.Documentation
Translation
Debugging
Execution &
Testing

Documentati
on

9847995577
1: Problem Identification
Real life Example:-
Suppose you are suffering from a stomach pain.

How can you solve this


problem?
This problem can be solved by a doctor.
Doctor may ask you some questions
regarding the duration of pain,
previous occurrence etc..
9847995577
 Examine some parts of your body using the
stethoscope, X-Ray or Scan.

(All these are the part of problem study)


 After these steps doctor may be identify the
problem .
The problem must be identified then only
it can be solved.

9847995577
2. Algorithms & Flow Chart
Algorithm:-
The Step-by-Step procedure to solve a problem is known as
algorithm.
E.g.:- Algorithm for Finding the Sum and Average
Procedure
Step 1: Input three numbers
Step 2: Add these numbers to get the sum
Step 3: Divide the sum by 3 to get the average
Step 4: Print sum and average
Algorithm
Step 1: Start
Step 2: input A,B,C
Step 3: S=A+B+C
Step 4: Avg=S/3
Step 5: Print S,Avg
Step 6: Stop 9847995577
E.g.:- 2 Write the algorithm for finding the area
and perimeter of a rectangle
o Perimeter=2(Length+Breadth),
o Area=Length X Breadth
Algorithm
Step 1: Start
Step 2: Input L,B
Step 3: P=2*(L+B)
Step 4: A=L*B
Step 5: Print P,A
Step 6: Stop

9847995577
Flowchart
The pictorial or Graphical representation of
an algorithm is known as Flowchart.
Flowchart Symbols
1. Terminal:-
It is used to indicate the beginning (START),
ending (STOP) of the program. It is the 1 st
symbol and last symbol in the flowchart.

9847995577
2. Input/Output:-
The parallelogram is used as the
input/output symbol. It denotes the
input/output device in the program.

3. Process:-
A rectangle is used to represent the
processing step. Arithmetic operations such
addition, subtraction, multiplication,
division are expressed using this symbol.

9847995577
4. Decision:-

The rhombus is used as decision symbol


and is used to indicate a point at which a
decision has to be made.
5. Flow Lines:-

Flow lines with arrow heads are used to


indicate the flow of operation.
6. Connector:-

It is represented by a circle and a letter


or digit is placed within the circle to indicate
the link.
9847995577
Symbols used in a Flowchart
Ellipse denotes the
terminal ie start
and stop Connectors for
denoting the
continuation to or
Parallelogram from the next or
for input and previous page
output.

Rectangle for
assigning values
and processing
Arrows to
denote
Diamond or Control flow
rhombus for
decision.
9847995577
Advantages of Flowcharts
Better Communication
Effective analysis
Effective synthesis (different modules can be
combined easily)
Efficient Coding

Limitation of Flowcharts
Time consuming Job
Modification requires ,new flowchart
No standard for amount of detail included
9847995577
Terminal
Start
Start/
E.g. Flowchart for Finding
Sum & Average of 3 numbers
Stop
Symbol
Input
A,B,C
Input/
output
Symbol
S=A+B+C
Avg=S/3

Process,
Print Including
S, Avg All
Arithmetic
Operations
Stop
9847995577
E.g. Find the area and perimeter of a rectangle
Start

Algorithm
Input
L,B
Step 1: Start
Step 2: Input L,B
Step 3:
P=2*(L+B) P=2*(L+B)
A=L*B
Step 4: A=L*B
Step 5: Print P,A
Print
P,A Step 6: Stop

Stop
9847995577
E.g. Find the biggest from Two numbers
Start

Input
A,B

Yes No
IF
A>B

Print A Print B
is Big is Big

Stop
9847995577
E.g. Check the given number is odd or Even
Start

Reminder can be calculate


Input N using Modulus operator
Like : % , Mod etc

No
Yes IF
Reminder*
of N/2 is 0

Print N Print N
is Even is Odd

Stop
9847995577
E.g. Find the biggest from three numbers
Start

Input
A,B,C

Yes No
IF
A>B
No No Yes
Yes
IF IF
A>C B>C

Print A Print C Print B


is Big is Big is Big

Stop
9847995577
E.g. FLOW CHART TO DISPLAY 1 TO 100
Start

N=1

Print
N1

N=N+1

Ye
IF s
N<=100
No

9847995577 Stop
E.g. FLOW CHART TO DISPLAY 1 TO 100
Start

N=1

Print
N1

N=N+1

Ye
IF s
N<=100
No

9847995577 Stop
E.g. FLOW CHART TO DISPLAY SUM OF FIRST 100 NUMBERS
Start

A=1
SUM=0

No
IF
A<=100

Ye
s
Print
SUM=SUM
SUM
+A

A=A+1 Stop

9847995577
E.g. FLOW CHART TO DISPLAY SUM OF FIRST N NUMBERS
Start
Input
N

A=1
SUM=0
No
IF
A<=N

Ye
s
Print
SUM=SUM
SUM
+A

A=A+1 Stop

9847995577
E.g. FLOW CHART TO DISPLAY MULTIPLES OF A NUMBER
Start
Input
N

A=1

M=A X N

Print
M

A=A+1

Ye
No s
IF
Stop A<=10
9847995577
3. Coding
The process of writing program instruction to
solve a problem is called coding.
The Program written in any HLL in known as
source code.
E.g. COBOL,C++, Pascal ,JAVA,VB etc

9847995577
4. Translation
It is the process of converting a program
written in high level language into machine
language.
The compiler or Interpreter is used for this
purpose.

Source Translatio Object


n
Code Code
Object Code is the Executable Machine code
9847995577
5. Debugging
Program errors are known as ‘bugs’ and the
process of detecting and correcting these errors is
called debugging.
Errors are two types,
1. Syntax Error
2. Logical Error
When the rules of the programming
language are not followed then syntax error
occurred. Eg: a+b=c
Correct code is c=a+b
When the logic of the program is wrong
then logic errors occurred. Eg: area=3.14+r*r (if
we want to find area of circle),correct code is
area=3.14*r*r
9847995577
6. Execution & Testing
It means running the program to give desired
input and get the corresponding output.

There is a chance of another type of error,


Run Time Error, this may be due to
inappropriate data.
Eg: result=A/(B-B) , where B-B become zero.
“File not found” is an another type of runtime
error

9847995577
7. Documentation
It is the process of providing sufficient
information in a program to understanding
its working to other programmers.like
system manual,user catalog, user
help(extrenal documentation)
We can also use comments enclosed in
special symbols inside the program code
(internal documentation).it can contains
details about programs/program
codes ,usages of codes etc

9847995577
THE END
Prepared By TCA Gafoor,
AKM HSS Kottoor,Malappuram
http://www.hsslive.in

You might also like