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

Chapter 4 (Principles of Programming and Problem Solving)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Chapter 4 (Principles of Programming and Problem Solving)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CHAPTER 4

PRINCIPLES OF PROGRAMMING AND PROBLEM SOLVING


Approaches in problem solving
• Top down design: A complex problem is broken down into different tasks and each task is
solved.
• Bottom up design: Solution for main module will be developed only after solving the sub
modules.

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

1. Ellipse: used to indicate START and STOP.


2. Parallelogram: used as the input/output symbol.

3. Rectangle: used to represent the processing step.

4. Rhombus: used as decision symbol.

5. Flow lines: used to indicate the flow of operation.

Advantages of flowchart Limitations of Flowchart


• Better communication • Time consuming
• Effective analysis • Modification is difficult
• Effective synthesis
• Efficient coding

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)

Source code -------> Translation ---------> Object code


Debugging
• Programming errors are known as 'bugs'. The process of detecting and correcting errors is
called debugging.

There are three types of errors:

• 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

Execution and testing


• Running the program to process the test data that will produce 'known results'.

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.

You might also like