Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 21

Chapter 1

Problem Solving Using


Computers
2 hours
~4-5 marks
Chapter Outlines
1. Problem Definition
2. Problem Analysis
3. Algorithm and Flowcharting
4. Coding
5. Compilation and Execution
6. Testing and Debugging
7. Program Documentation
1.1 Problem analysis
• Understanding what a problem is and what it demands (as an answer)
• Analysis of system, requirements, available resources and constraints
• It includes study of problem’s inputs and outputs, ways of solving
problem, efficiency among various alternative approaches, etc.

E.g. A stone is thrown upwards with a velocity of 25 m/s from a building of height
100m. Similarly, a ball is thrown upwards from the ground with a velocity of 30m/s.
Calculate the time and distance where the ball and stone will meet.

Analysis: initial velocity and heights are given. Since the motion is upward, acceleration
due to gravity is to be considered. At certain time, distance covered by both objects will
be same. Hence we can equate the distance covered by both objects (s1 and s2).
1.2 Algorithm Development and Flowcharting
• Algorithm is a step-by-step description of the procedure written in human
understandable language
• A set of instructions which, when executed in a certain sequence, will fulfill a
particular objective (i.e., solving a particular problem)
• Sequential order for solving a problem

• E.g. Algorithm to compute average of 3 given numbers.



1. Start
2. Define num1, num2, num3, & avg
3. Input num1, num2, and num3
4. Calculate avg=
5. Display avg as the average of 3 numbers.
6. Stop
Steps in algorithm [Algorithm Flow/Sequence]
• We know that any computer system consists of input, processing, and
output facilities. (sometimes storage may occur too)

• Sequence within an algorithm prescribe same facilities in a certain order.

Define Read Loops /


Calculation Storage Display
container values Conditions

Start Input Processing Output Stop

5
Rules for writing an algorithm
1. An algorithm should always consist of Start and Stop points.

2. Language for algorithm must be kept simple and easy to


understand.

3. Ambiguous terms (terminologies with unclear or multiple


meanings) should be avoided.

4. All the steps should be precisely explained. Processing mechanism


cannot contain hidden activities.
Rules for writing an algorithm
5. If iterative operations are performed within an algorithm, their
termination conditions must be well-defined. This is to ensure that
the algorithm reaches Stop point with certainty.

6. An algorithm must eventually terminate after certain processes are


executed. It cannot work forever without halting.

7. After all processes are followed, the resulting output must act as a
solution to the specified problem.
Flowchart
• Pictorial representation of algorithm

• Use of standard shapes for diagrammatic explanation of how the system


solves the particular problem

• Flowchart makes it easier to translate lengthy and complex algorithm


instructions into simpler structures.
• This helps in carrying software development process forward.

• A flowchart can be helpful for both writing programs and explaining the
program to others.
Symbols in flowchart

9
When are these symbols used?

10
Start

Examples in Flowcharts
Define I, T, R, P

A. Algorithm to calculate simple interest


1. Start
Read P, T, R
2. Define I, T, R, P
3. Read P, T, R
I = (P*T*R)/100
4. I = P*T*R/100
5. Display I
6. stop Display I

Stop

11
Start

Define a, b, avg

B. Algorithm to find average of 2 numbers


1. Start
Read a, b
2. Define a, b, avg
3. Read a, b
avg = (a + b)/2
4. avg = (a+b)/2
5. Display avg
6. stop Display avg

Stop

12
Things to consider in flowcharting
1. A flowchart always starts from Start/Begin box and always ends in
Stop/End box.

2. All shapes or boxes within a flowchart are connected to at least one


other shape or box through directed arrows.

3. Flow of control always moves from top to bottom.


• If flowchart cannot be contained in a single page, connector symbols can be
used.

4. Each mechanism has its specified symbol for representation.


1.3 Coding

• Use of programming language to develop the software system

• Process of transforming paper-based development logic/design into a


computer language format.

• This phase converts each boxes of flowchart into various programming


statements.

• There are many programming languages available. However, coding


requires knowledge of at least 1 computer language.

• Programs can be of different complexity, generation, or ease.


1.4 Compilation and Execution
• Compilation is the process of Collection/Integration of codes to form a single
program

• It converts high level language (instruction written in human-understandable


language) into machine level language (instruction in computer-understandable
language)

• Compilation checks if the program contains error in the syntax or not.


If errors exist, programmer/user is notified about the error. The program will not progress
any further.

• If errors are not detected, programs are compiled, and the program is loaded into
computer’s memory.
This process is called execution
1.5 Testing and Debugging
• Even if the program runs, it still might contain some unwanted
interaction/behavior which is discovered later.
Testing is done to ensure that the program runs free of errors during run-time.

• If bugs exist, a process of removing bugs, also known as debugging, is


performed.
Debugging is the discovery and correction/removal of logical errors.

• Testing and debugging is a continuous process.


Types of errors
• Logical error
• Error that is not detected by compiler, but is seen during output (wrong
answer)
• Also called semantic error
• E.g. displaying a-b as sum of numbers a and b

• Syntax Error
• Error occurred due to faulty syntax written by programmer
• Detected by compiler
• E.g. missing a semicolon or comma, writing “pruntf” instead of “printf”
Testing approaches
1. Black box testing
• Give input and see the output
• Knowledge of code or how inner programming works is not required
• Useful for beginners

2. White box testing


• Analyze how code flows between the lines
• Knowledge of coding as well as flow of code is required
• Useful for skilled programmers as the errors and issues can be efficiently
detected as well as addressed.
1.7 Program Documentation
• It contains program description and logic, programmer details,
functions and features of program, program usage guides,
troubleshooting guides, Frequently Asked Questions etc.

• A good documentation simplifies maintenance and redesign, and


makes subsequent programming tasks much simpler.

• It helps to those who use, maintain, and extend the program in


future.
Important questions
• Very Short Questions [2 marks]
1. Define algorithm and flowcharting.
2. Discuss the rules for writing algorithm.
3. Why is testing an important phase in system development?
4. Define compilation and execution process.

• Short Questions [4 marks]


1. Describe various problem solving steps used in computing.
2. Write an algorithm to find if a user given number is divisible by 3 or not
3. Draw a flowchart to find average of 3 given numbers.

You might also like