006 Problem Solving & Decomposition-FILE
006 Problem Solving & Decomposition-FILE
REQUIREMENT
S
ANALYSIS
DESIGN
CODING
TESTING
IMPLEMENTATION
DOCUMENTATION
REQUIREMENTS
What the problem is?
What is needed to solve it?
What the solution should
provide
If there are constraints and
special conditions?
ANALYSIS
INPUTS: To the problem, their
and the input form to be used.
OUTPUTS: Expected media from
the problem, their form and the
output media to be used.
Special constraints or (necessity)
conditions (if any).
Formulas or equations to be used
DESIGN
In Design phase, we design the
proposed solution without writing a
computer program by using the
techniques:
◦ Algorithm
◦ Pseudocode
◦ Flow Chart
Coding
It is the process of transforming
design (Algorithm, Pseudocode,
Flow Chart) in a computer program
using any programming language.
The output of program must be the
solution of intended problem.
Testing
Program testing is the process of
executing a program to demonstrate
its correctness.
Program verification is the process
of ensuring that a program meets user
requirement
After the program is compiled we must
run the program and test/verify it
with different inputs before the
program can be released to the
public or other users (or to the
instructor of this class)
Implementation
It is the process of installing
the software developed on
customer‟s site.
Installation may be done by replace
the entire manual work with the
software developed or in a pilot
mode i.e. running the manual and
automated system in parallel or
installing only a part module
with manual work.
It also involves training of
software to the intended users.
Documentation
-Contains details produced at all stages
of the program development cycle.
Can be done in 2 ways
* writing comments between your line
of codes.
* Creating a separate text file to
explain the program.
-Important not only for other people to
use or modify your program, but also for
you to understand your own program after
along time.
Algorithm
An algorithm is a list of steps to be
executed with the right order in which
these steps should be executed.
According to D.E. Knuth, an algorithm
has the following characteristics:
An algorithm has fixed number of steps.
Each step in an algorithm specifies the
action to be performed.
The steps in an algorithm
specify basic operations.
An algorithm accepts input data.
An algorithm generates one or more
outputs after the input is processed
Algorithm to withdraw money from ATM
The algorithm to withdraw a required amount from an
ATM will be:
1. Start the algorithm.
2. Go to any local ATM.
3. Insert/swipe your ATM card.
4. Press the language button that you want to choose.
5. Enter the pin code number.
6. Press the account type (Savings or Current) button from
which you want to withdraw the money.
7. Press the cash withdrawal button.
8. Enter the amount you want to withdraw.
9. Collect the amount from the ATM machine.
10.Collect the statement from the ATM machine.
11.Collect your ATM card.
12.End the algorithm.
Algorithm of getting out of bed and
prepare to go to work
1. Get out of Bed.
2.Take Shower.
3. Get Dressed
72 9 8
Solution - 2
1.Start the algorithm.
2.Get the distance in kilometers.
3.Multiply the distance by 1000.
4.Display the result of
multiplication as distance in
meters.
50
5.End the algorithm.
50 1000 50000
ADVANTAGES
It helps in analyzing the problems effectively.
It acts as a guide during the program
development phase. It help easy debugging of
logical errors
DISADVANTAGES
A lengthy flowchart may extend over multiple pages, which
reduces readability.
Drawing a flowchart is time consuming.
The changes made to a single step may cause redrawing the
entire
flowchart
Flowchart Symbols
Flowchart Symbols
Start A
Accept a
number
Display the
number
Stop
Consider an example where you need to determine whether a
number is even or odd.This problem can be solved based on
the condition that the number should be divisible by 2. If
the number is divisible by 2, it should display the
message, „The Number is Even‟, otherwise „The Number is
Odd‟.
Start
Accept a number
Stop
Just a Minute…
Write a flow chart to calculate
area of rectangle
◦ Allotted Time: 05 minutes
Write a flow chart to enter any
number and check it is divisible by
7 or not
◦ Allotted Time: 05 minutes
Solution - 1
Start
Accept length,
breadth
DisplayArea
Stop
Solution - 2
Start
Accept a number
No
Display
Is the remainder ‘Number not
equal to zero ? divisible by
Yes 7’
Display ‘Number
divisible by 7’
Stop
Pseudocode
It is a formal way of writing the program
logic whereas algorithm is an informal way
of writing program logic
It is detailed yet easy description of
what algorithm must do.
It is written in formally styled-English
language
It is used as an initial step in the
process of developing of program
Provide detailed template to programmers.
It is language independent i.e. it can be
converted to program by using any
programming language.
Pseudocode
In Pseudocode we can use few special
words for determining the actions
like
◦ Accept/input
◦ Display/print
◦ If / else
◦ Repeat
◦ Start
◦ End
◦ Goto
Example – to input 2 number and
display the sum
1. START
2. INPUT A,B
3. TOTAL = A +B
4. PRINTTOTAL
5. END
Example – to enter a number and
check it is even or odd
1. START MOD (%) is used to find
out
2. INPUT NUM remainder by dividing 2
1. START
2. A =1 [INITIAL VALUE]
3. WHILEA<=100 [CONDITION]
4. PRINTA
5. A =A +1 [INCREMENT]
6. END
Disadvantages
The solution to subprogram might not combine
to solve the original problem
Poorly understood problems are hard to
decompose
Need of Decomposition
As studied earlier, first need of
decomposition is to divide the large
program into smaller and manageable sub
program, it is easier to write 2
programs of 400 lines than writing
single program of 800 lines.
Each subprogram can be managed
independently
Global changes can be applied very easily
Code can be reused
Functions, modules, class are some
example of decomposition.
Decomposition Example- 1
Decomposition Example- 2
LIBRARY M A N A G E M E N T
DELETE DELETE