Chapter 4 (Principles of Programming and Problem Solving)
Chapter 4 (Principles of Programming and Problem Solving)
Phases in programming
• Problem identification
• Preparing Algorithms and Flowcharts
• Coding the program
• Translation
• Debugging
• Execution and testing
• Documentation
Problem Identification
• In this phase we will be able to identify the data involved in processing, its type and quantity,
formula to be used, activities involved, and the output to be obtained.
Algorithm
• It is a step-by-step procedure to solve a problem.
Characteristics of an Algorithm
• Should begin with instructions to accept inputs.
• Use variables to refer the data
• Each and every instruction should be precise and unambiguous.
• The total time to carry out all the steps in the algorithm must be finite.
• After performing the instructions given in the algorithm, the desired results must be
obtained.
Flowcharts
• The pictorial representation of an algorithm is known as flowchart.
Flowchart symbols
Eg: Write an algorithm and draw a flowchart to find the sum of two numbers
Step 1: Start
Step 2: Input A, B
Step 3: S = A + B
Step 4: Print S
Step 5: Stop
Eg: Write an algorithm and draw a flowchart to find the sum and average of three
numbers
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
Eg: Write an algorithm and draw a flowchart to find the biggest of two numbers.
Step 1: Start
Step 2: Input N1, N2
Step 3: If N1 > N2 Then
Step 4: Print N1
Step 5: Else
Step 6: Print N2
Step 7: End of If
Step 8: Stop
Eg: Write an algorithm and draw a flowchart to print the sum of the first N natural
numbers
Step 1: Start
Step 2: Input N
Step 3: A = 1, S = 0
Step 4: Repeat Steps 5 and 6 While (A <= N)
Step 5: S = S + A
Step 6: A = A + 1
Step 7: Print S
Step 8: Stop
Coding
• The process of writing program instructions to solve a problem using a High Level Language.
Translation
• Process of converting a program written in high level language(source code) into its
equivalent version in machine language(object code)
• Syntax errors: Errors which occur when the rules or syntax of the programming language
are not followed.
• Logical errors: Logical error is due to improper planning of the program logic.
Run-time errors: Errors which occur during program execution. Eg:- division by zero
Documentation
• Writing comments in the source code is known as internal documentation.
• It will help in debugging process and program modification at later stage.
• Preparing user manual and system manual are known as external documentation.