Chapter 1: Problem Solving Approach Using Computers
Chapter 1: Problem Solving Approach Using Computers
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
5
Rules for writing an algorithm
1. An algorithm should always consist of Start and Stop points.
7. After all processes are followed, the resulting output must act as a
solution to the specified problem.
Flowchart
• Pictorial representation of algorithm
• 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
Stop
11
Start
Define a, b, avg
Stop
12
Things to consider in flowcharting
1. A flowchart always starts from Start/Begin box and always ends in
Stop/End box.
• 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.
• 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