Problem Solving - Part1
Problem Solving - Part1
Programming Languages
and Program Development
Processing
◼ how do you go from inputs to outputs?
A defining diagram is recommended
circumference = 2 * P I* radius
area=PI * radius ^ 2
O: radius, circumference, area
Implementation phase
implement the program in some programming
language
NOT a
language
syntax
A Flowchart
shows logic of an algorithm
emphasizes individual steps and their
interconnections
e.g. control flow from one action to the next
Example:
Average of 3 numbers
Algorithm Flowchart
Step 1: Input Lft
START
Step 2: Lcm Lft x 30
Input
Step 3: Print Lcm Lft
Lcm Lft x 30
Print
Lcm
STOP
Prepared by Dr. Walaa Khaled
Example 3
27
Print A
Algorithm START
Step 1: Input W,L
Input
Step 2: AL x W W, L
Step 3: Print A
A LxW
Print
A
STOP
Prepared by Dr. Walaa Khaled
Example 4
Pseudocode:
Input the coefficients (a, b, c) of the quadratic
equation
Calculate d
Calculate x1
Calculate x2
Print x1 and x2
Print
x1 ,x2
STOP
READ
Algorithm: PRICE
SALE = PRICE ´
QUANTITY
Print
SALE
STOP
START A
READ SALE =
UNIT PRICE UNITPRICE * QUANTITY
READ Print
QUANTITY SALE
A STOP
Input
M1,M2,M3,M4
Step 1: Input M1,M2,M3,M4
Step 2: GRADE (M1+M2+M3+M4)/4
GRADE(M1+M2+M3+M4)/4
Step 3: if (GRADE <60) then
Print “FAIL”
else N IS Y
Print “PASS” GRADE<60
endif
PRINT PRINT
“PASS” “FAIL”
STOP
Operator Description
> Greater than
< Less than
= Equal to
Greater than or equal to
Less than or equal to
Not equal to
Prepared by Dr. Walaa Khaled 40
Example 7
41
Algorithm
Step 1: Input VALUE1, VALUE2
Step 2: if (VALUE1 > VALUE2) then
MAX VALUE1
else
MAX VALUE2
endif
Step 3: Print “The largest value is”, MAX
Prepared by Dr. Walaa Khaled
Example 7 START
Input
VALUE1,VALUE2
Y is N
VALUE1>VALUE2
Print
“The largest value is”, MAX
STOP
43 Prepared by Dr. Walaa Khaled
Example
44