Documente Academic
Documente Profesional
Documente Cultură
Problem Solving
PSPD Using C
PSPD Using C
Problem Solving
Design
PSPD Using C
Problem Solving
Design
DEVISING A PLAN
Second:
Find the connection
between the data and
the unknown.
Auxiliary problems
may be devised if
needed.
You should obtain
eventually a plan of
the solution.
PSPD Using C
Problem Solving
Design
Third:
Fourth:
LOOKING BACK
Examine the
solution
obtained.
PSPD Using C
Problem Solving
Design
Algorithmic problem:
Any problem whose solution can be expressed as a
set of executable instructions.
Algorithm:
A well defined computational procedure consisting of
a set of instructions, that takes some value or set of
values, as input, and produces some value or set of
values, as output.
PSPD Using C
Derived from the name of Mohammed alkhowarizmi, a Persian mathematician in the ninth
century.
Al-khowarizmi--Algorismus(in Latin)--Algorithm
An algorithm is like a recipe, that converts the
ingredients into some culinary dish.
The formal written version is a program.
Algorithms/programs are the software.The machine
that runs the programs is the hardware.
PSPD Using C
Ingredient
Recipe
(software)
Cooking utensils
(hardware)
Al-gong
Bah-kut-the
PSPD Using C
Characteristics of an Algorithm
Design
PSPD Using C
Characteristics of an Algorithm
Design
PSPD Using C
Characteristics of an Algorithm
Design
An Algorithm
PSPD Using C
Problem Solving
Design
PSPD Using C
Problem Solving
Design
=
PSPD Using C
Problem Solving
Design
Processing
(Brains)
Input
Output
PSPD Using C
Problem Solving
Output Device
CPU
(Brains)
Input Device
PSPD Using C
Design
Problem Solving
Design
Processing
10
5 + 10 = 15
15
Input
Output
Let us assume we are interested in calculating the sum of 5
and 10.
PSPD Using C
Problem Solving
Design
PSPD Using C
Problem Solving
Design
Value2
Value1
Sum
Notice that instead of using specific numbers,
variables are used to represent these values.
PSPD Using C
PSPD Using C
Problem Solving
Design
Input
Value1
Value2
PSPD Using C
Processing
Output
Sum
Problem Solving
Design
Processing
Value1
Value2
2) Calculate Sum
3) Display Sum
PSPD Using C
Output
Sum
Algorithm Development
Once the defining diagram has been
developed, the next logical step is to develop
the algorithm (which is much more detailed).
Input
Processing
Value1
Value2
2) Calculate Sum
Output
Sum
3) Display Sum
Design
Algorithm Development
Design
PSPD Using C
addition
subtraction
multiplication
division
assignment
()
Algorithm Development
Design
2)
Calculate
Sum = Value1 + Value2
3)
PSPD Using C
Display Sum
Pseudocoding
Design
A Pseudocode language is semiformal, Englishlike language with a limited vocabulary that can be
used to design and describe algorithms.
The pseudocode language can be used for:
Designing algorithms
Communicating algorithms as programs
Implementing algorithms as programs
Debugging logic errors in program
PSPD Using C
PSPD Using C
Contd
Design
if condition
then-part
else
else-part
end-if
PSPD Using C
Decision Making
Design
in
Decision Making
Design
IF (expression) THEN
:
:
ENDIF
Statements are
placed here.
PSPD Using C
Decision Making
Design
IF (Salary>4000) THEN
Say "I Will Take The Job!!"
ENDIF
PSPD Using C
Decision Making
Design
Greater Than
<
Less Than
Equals To
<>
Not Equals To
>=
<=
()
PSPD Using C
Decision Making
Design
Decision Making
Design
Decision Making
Design
OR
NOT
PSPD Using C
Decision Making
Design
PSPD Using C
Decision Making
For example, this statement.........
Design
Decision Making
For good practice...........
Design
IF (Salary>4000) THEN
IF (CreditCard=YES) THEN
Say Yes I Will Take The Job!!
ELSE
Say No Credit Card?
Say Sorry!!
ENDIF
ELSE
Say Not Enough Pay!!
ENDIF
Contd
Design
For Example:
if a is greater than b then
print A is greater
else
print B is greater
end if
PSPD Using C
Contd
Design
PSPD Using C
Looping Constructs
Design
PSPD Using C
Looping Constructs
Design
PSPD Using C
Looping Constructs
Design
DOWHILE...ENDDO
FORNEXT
REPEAT...UNTIL
PSPD Using C
Looping Constructs
Design
Looping Constructs
Design
Looping Constructs
Design
Looping Constructs
Design
Take a look at the following example:You are required to develop a complete system
which will allow the total payroll to be
calculated.
The system is required to read in the amount to
be paid for each employee.
The moment the system receives an input
value of -99, the system is required to stop and
display the total payroll.
PSPD Using C
Looping Constructs
Design
Processing
1) Read Salary
2) Calculate Total
3) Display Total
PSPD Using C
Output
Total
Looping Constructs
Algorithm (Using Pseudocodes)
1) Display "Enter Salary"
2) Read Salary
3) Total = 0
4) DOWHILE (Salary<>-99)
Total = Total + Salary
Display "Enter Salary"
Read Salary
ENDDO
5) Display "Total Payroll = ", Total
PSPD Using C
Design
Contd
Design
Example:
Dowhile (income is less than 50000)
print Enter taxable income;should be
greater than or equal to 50000
read income
Enddo
PSPD Using C
Processing
Value1
Value2
2) Calculate Sum
Design
Output
Sum
3) Display Sum
Processing
Value1
Value2
2) Calculate Sum
Output
Sum
3) Display Sum
Value2
Sum
Calculate
Display
Value2
Sum
13
Calculate
21
Display
15
Value2
Sum
Calculate
24
Display
Program Flowcharts
Design
PSPD Using C
Program Flowcharts
The following are the commonly used
symbols for drawing program flowcharts.
terminator
off-page
connector
process
storage
decision
making
document
input/output
connector
arrowheads
PSPD Using C
Design
Program Flowcharts
Begin
Read Value1,
Value2
Calculate
Sum = Value1 + Value2
Display
Sum
End
PSPD Using C
Design
Program Flowcharts
Begin
Design
Read Amount
YES
Amount>20.00?
Calculate
Actual=Amount * 0.80
Calculate
Actual=Amount
End
PSPD Using C
NO
Flowcharting
Design
Alternative to pseudocoing
A pseudocode description is verbal, a flowchart is
graphical in nature.
Definition:
PSPD Using C
Sequence Structure
Design
Pseudocode:
statement_1
Flowchart:
Statement -1
statement_2
------------
Statement -2
statement_n
Statement -n
PSPD Using C
Selection Structure
Design
Pseudocode:
Flowchart:
if condition
then-part
else
false
else-part
end_if
PSPD Using C
else-part
condition
true
then-part
Selection Structure
Design
Pseudocode:
Flowchart:
if condition
then-part
end_if
condition
N
false
PSPD Using C
true
then-part
Repetition Structure
Design
Pseudocode:
Flowchart:
while condition
loop-body
end-while
condition
F
N
PSPD Using C
loop-body
Summary
Design
PSPD Using C
Summary
Design
PSPD Using C
1.
2.
3.
Summary
Design
4.
5.
6.
7.
PSPD Using C
Summary
Design
PSPD Using C
Summary
Design
PSPD Using C
PSPD Using C
Follow Up Assignment
Design
PSPD Using C
Problem Solving
Pseudocodes
Flowcharts
PSPD Using C