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

Lecture Stage of Problem Solving

Uploaded by

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

Lecture Stage of Problem Solving

Uploaded by

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

Problem Solving with

Computer

1
Introduction
• Number of problems in our daily life.
• Suppose we have to calculate Simple
Interest.
• Suppose we have to prepare a mark
sheet.
• A computer cannot do anything alone
without software i.e. Program

2
• A software is a set of programs written
to solve a particular problem

• Software is a set of instructions on the


basis of which computer gives
output/result.

• If the instructions are not correct,


the computer gives wrong result.

3
Never Ever Forget
• Just writing code is not sufficient to
solve a problem.

• Program must be planned before


coding in any computer language
available.

• There are many activities to be done


before and after writing code.
4
Stages while solving a problem using
computer
1. Problem Analysis
2. Algorithm Development
3. Flowcharting
4. Coding
5. Compilation and
Execution
6. Debugging and Testing
7. Documentation
5
Problem Analysis

Algorithm Development

Flowcharting

Program Coding

Compilation and Execution

Debugging and Testing

Documentation

Steps in problem solving


6
1. Problem Analysis
• Process of becoming familiar with the problem.

• We need to analyze and understand it well


before solving.

• The user’s requirements cannot be fulfilled without


clear understanding of his/her problem in depth.

• Inadequate identification of problem may


cause program less useful and insufficient.

• Example: Banking Solution, Hospital Medical Study

7
2. Algorithm Development
• Step By Step description of the
method to solve a problem.

• Effective procedure for solving a


problem in finite number of steps.

• Developing an algorithm is a step of


program design.
8
An algorithm to find sum of two
numbers:
Step 1: Start

Step 2: Assume two numbers x and y and a variable


sum=0

Step 3: Add two numbers x and y; store the value in


variable sum

Step 4: If you want to try again with different


numbers then goto step 2
else
goto step 5
Step 5: END 9
An algorithm to find sum of two
numbers:
Step 1: Start
Step 2: Declare variables num1, num2 and
sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to
sum. sum←num1+num2
Step 5: Display sum
Step 6: Stop

10
An algorithm to find largest of three
different numbers:

11
Three features of Algorithm
• 1. Sequence
– Each step in the algorithm in executed in specified order. If not algorithm
will fail.
• 2. Decision
– We have to make decision to do something.
– If the outcome of the decision is true, one thing is done otherwise other.
• If condition then process1
OR
• If condition
then process1
Else process2
• 3. Repetition
– For example,
Repeat
Fill Water in the kettle
Until Kettle is full

12
3. Flowcharting
• Graphical representation of an algorithm using
standard symbols.

• Includes a set of various standard shaped boxes


that are interconnected by flow lines.

• Flow lines have arrows(direction of flow).

• Activities are written within boxes in English.

• Communicates between programmers and


business persons.

13
Advantages of Flowcharts
• Communication
– Quickly provide logic, ideas and descriptions of
algorithms.
• Effective Analysis
– Clear overview of the entire problem.
• Proper Documentation
– Documents the steps followed in an algorithm.
– Helps us understand its logic in future.
• Efficient Coding
– More ease with comprehensive flowchart as a guide
• Easy in debugging and program
maintenance
– Debugging and maintenance of operating program 14
Flowchart
Symbols

15
Things to consider
• There should be start and stop to the
flowchart.

• Only one flow line should emerge


from a process symbol.

• Only one flow line should enter a


decision symbol, but two or three flow
lines can leave the decision symbol.
16
Problem: Write an algorithm and draw
flowchart for finding the sum of any two
numbers.
Algorithm

Step1: Start
Step2: Display “Enter two
numbers”.
Step3: Read A and B
Step4: C= A+B
Step5: Display “C as sum of two
numbers”
17
Step6: Stop
Flowchart
START Start

Read two
Numbers, A and
Input
B

C=A+B Processing

Display C as Sum of A
and B
Output
END End
18
4. Coding
• The process of transforming the program logic
design into computer language format.

• An act of transforming operations in each box of the


flowchart in terms of the statement of the program.

• The code written using programming language is also


known as source code.

• Coding isn’t the only task to be done to solve a problem


using computer.

• Anyone can code. TRUST ME!!


19
Compilation
• Process of changing high level language into
machine level language.

• It is done by special software, COMPILER

• The compilation process tests the program whether it


contains syntax errors or not.

• If syntax errors are present, compiler can not


compile the code.

20
Execution
• Once the compilation is completed then the
program is linked with other object programs
needed for execution, there by resulting in a
binary program and then the program is loaded
in the memory for the purpose of execution and
finally it is executed.

• The program may ask user for inputs and


generates outputs after processing the inputs.

21
Debugging and Testing

• Debugging is the discovery and


correction of programming errors.

• Some errors may remain in the program


because the designer/programmer might have
never thought about a particular case.

• When error appears debugging is necessary.

22
Debugging and Testing
• Testing ensures that program performs correctly
the required task.

• Verification ensures that program does what


the programmer intends to do.

• Validation ensures that the program produces


the correct results for a set of test data.

• Test data are supplied to the program and


output is observed.

• Expected output = Error free


23
Program Documentation
• Helps to those who use, maintain and extend
the program in future.

• A program may be difficult to understand


even to programmer who wrote the code
after some days.

• Properly documented program is


necessary which will be useful and
efficient in debugging, testing,
maintenance and redesign process.
24
Two types of documentations

1. Programmer’s Documentation
(Technical Documentation)
• Maintain, redesign and upgrade
• Logic, DFD, E-R, algorithm and flowchart
2. User Documentation (User Manual)
• Support to the user of the program
• Instructions for installation of the program

25
Compiler
• A high level source program must be translated into a form
machine can understand. This done by software called the
compiler.

• Source code => Machine language code(Object code)

• During the process of translation, the compiler reads the


source
programs statement-wise and checks for syntax errors.

• In case of any error, the computer generates message


about the error.

• Ex: C, C++, Java, FORTRAN, pascal etc.


26
Interpreter
• Like compiler, it is also a translator which translates high
level to machine level language.

• Translates and executes the program line by line.

• Each line is checked for syntax error and then converted


to the equivalent machine code.

• Ex. QBASIC, PERL, PHP, ASP, PYTHON, RUBY

27

You might also like