Lecture - 05 - 11
Lecture - 05 - 11
Programming Fundamentals
Contents
2
Problem analysis tools
3
Problem analysis tools
• Problem analysis tools help you analyze the problem to have a clear picture
of the problem.
• They help you identify the problems and their causes at the beginning.
• They help you better understand the problem by conducting its postmortem.
4
Problem analysis tools
• The problem analysis tools that we will be using to solve problem are:
Flow
IPO Charts Algorithms
Charts
5
IPO Chart
6
IPO Chart
Algorithm:
7
IPO Chart
• The input section specifies all the inputs to the problem.
• The input may be given by the user from input devices like, keyboard,
mouse, scanner etc.
• The output may be in the form of the presenting the results on the monitor
screen, printer or any other output device.
• The processing section specifies two things: processing items and algorithm.
• The algorithm is the step by step processing procedure to solve that task.
10
Algorithm
11
Algorithm
• For example, calculating the average of three numbers.
12
Flow Chart
• All the symbols are then connected with arrows to show the flow of the
process.
13
Flow Chart
Symbol Name Meaning
14
Flow Chart
Symbol Name Meaning
Input-Output
Shows an input or output instruction.
(Parallelogram)
15
Flow Chart
Symbol Name Meaning
16
Flow Chart
Symbol Name Meaning
17
Problem Examples
IPO Charts, Algorithms and Flow Charts
18
Problem 01: Area of rectangle
19
Problem 01 - IPO Chart and Algorithm
Algorithm:
Step 01: Start
Step 02: Input width and height from the user
Step 03: Calculate area as: area = width * height
Step 04: Print area
Step 05: End
20
Problem 01 – Flow Chart
21
Problem 02 : Average of three numbers
22
Problem 02 - IPO Chart and Algorithm
Input Processing Output
• First number Processing Items: • Average of numbers
• Second number average = (number1 + number2 + number3)/3
• Third number
Algorithm:
Step 01: Start
Step 02: Input number1, number2 and number3
from the user
Step 03: Calculate average as: average =
(number1 + number2 + number3)/3
Step 04: Print average
Step 05: End
23
Problem 02 – Flow Chart
24
Problem 03 : Temperature scale conversion
25
Problem 03 - IPO Chart and Algorithm
Input Processing Output
• Temperature in Processing Items: • Temperature in
Celsius F = C * 1.8 + 32 Fahrenheit
K = C + 273.15 • Temperature in
Kelvin
Algorithm:
Step 01: Start
Step 02: Input Celsius c from the user
Step 03: Calculate Fahrenheit temperature as:
f = (c * 1.8) + 32
Step 04: Calculate Kevin temperature as:
k = c + 273.15
Step 05: Print f and k
Step 06: End
26
Problem 03 – Flow Chart
27
Problem 04 : Area and circumference of a
circle
28
Problem 04 - IPO Chart and Algorithm
Input Processing Output
• Radius of circle Processing Items: • Area of circle
area = π * radius^2 • Circumference of
circumference = 2 * π * radius circle
Algorithm:
Step 01: Start
Step 02: Input radius from the user
Step 03: set PI = 3.1415
Step 04: Calculate area as: area = PI * radius^2
Step 05: Calculate circumference as:
circumference = 2 * PI * radius
Step 06: Print area and circumference
Step 07: End
29
Problem 04 – Flow Chart
30
Problem 05 : Buntty, Bubbly and Building
31
Problem 05 - IPO Chart and Algorithm
Input Processing Output
• Distance • Distance of
between Bubbly from
Buntty and the building
Bubbly
• Height of the
Building
32
Problem 05 - IPO Chart and Algorithm
Input Processing Output
Step 04: Print Dis_Bub_Bui
Step 05: End
33
Problem 05 – Flow Chart
34
Problem 06 : Even or odd number
35
Problem 06 - IPO Chart and Algorithm
Input Processing Output
• Integer number Processing Items: • Number is
If (number MOD 2) = 0 then it is even odd or even
If (number MOD 2) ≠ 0 then it is odd
Algorithm:
Step 01: Start
Step 02: Input number from the user
Step 03: if (number MOD 2) == 0 then GOTO Step 04
else GOTO Step 05
Step 04: Print “Number is even” GOTO Step 06
Step 05: Print “Number is odd”
Step 06: End
36
Problem 06 – Flow Chart
37
Problem 07 : Positive numbers
38
Problem 07 - IPO Chart and Algorithm
Input Processing Output
• Integer number Processing Items: • Number if it is
If (number > 0) then it is positive positive
Algorithm:
Step 01: Start
Step 02: Input number from the user
Step 03: if (number > 0) then GOTO Step 04 else GOTO
Step 05
Step 04: Print number
Step 05: End
39
Problem 07 – Flow Chart
40
Problem 08 : Largest number
41
Problem 08 - IPO Chart and Algorithm
Input Processing Output
• First number Processing Items: • Largest
• Second number If (num1> num2 and num1 > num3) then num1 is largest number
• Third number If (num2> num1 and num2 > num3) then num2 is largest
If (num3> num1 and num3 > num2) then num3 is largest
Algorithm:
Step 01: Start
Step 02: Input num1, num2 and num3 from the user
Step 03: if (num1> num2 and num1 > num3) then GOTO
Step 05
Step 04: if (num2> num1 and num2 > num3) then GOTO
Step 06 else GOTO Step 07
42
Problem 08 - IPO Chart and Algorithm
Input Processing Output
Step 05: Print num1 GOTO Step 08
Step 06: Print num2 GOTO Step 08
Step 07: Print num3
Step 08: End
43
Problem 08 – Flow Chart
44
Problem 9 : Marks sheet
45
Problem 9 - IPO Chart and Algorithm
Input Processing Output
• Marks of first Processing Items: • Percentage
subject Percentage = (Obtained marks/Total marks)*100 of marks
• Marks of second If(Percentage >= 85) grade = A+ • Grade
subject If(Percentage >= 80 and Percentage <= 84) grade = A obtained
• Marks of third If(Percentage >= 75 and Percentage <= 79) grade = B+
subject If(Percentage >= 70 and Percentage <= 74) grade = B
• Marks of fourth If(Percentage >= 65 and Percentage <= 69) grade = C+
subject If(Percentage >= 60 and Percentage <= 64) grade = C
• Marks of fifth If(Percentage >= 55 and Percentage <= 59) grade = D+
subject If(Percentage >= 50 and Percentage <= 54) grade = D
If(Percentage <= 49) grade = F
46
Problem 9 - IPO Chart and Algorithm
Input Processing Output
Algorithm:
Step 01: Start
Step 02: Input marks of subjects sub1, sub2, sub3, sub4 and sub5
from the user
Step 03: Calculate percentage as :
per = ((sub1 + sub2 + sub3 + sub4 + sub5)/500)*100
Step 04: If (per>=85) then grade=“A+” GOTO Step 10
Step 05: If (per>=80 and per<=84) then grade=“A” GOTO Step 13
Step 06: If (per>=75 and per<=79) then grade=“B+” GOTO Step 13
Step 07: If (per>=70 and per<=74) then grade=“B” GOTO Step 13
Step 08: If (per>=65 and per<=69) then grade=“C+” GOTO Step 13
Step 09: If (per>=60 and per<=64) then grade=“C” GOTO Step 13
Step 10: If (per>=55 and per<=59) then grade=“D+” GOTO Step 13
Step 11: If (per>=50 and per<=54) then grade=“D” GOTO Step 13
47
Problem 9 - IPO Chart and Algorithm
Input Processing Output
Step 12: If (per<=49) then grade=“F”
Step 13: Print per, grade
Step 14: End
48
Problem 9 – Flow Chart
49
Problem 9 – Flow Chart
Zoom-In to have a
clear view
50
Problem 10 : First 10 integer numbers
51
Problem 10 - IPO Chart and Algorithm
Input Processing Output
Processing Items: • First 10
1, 2, 3, . . . , 10 integer
numbers
Algorithm:
Step 01: Start
Step 02: Set i = 1
Step 03: Repeat Step 04 to Step 05 while i <=10
Step 04: Print i
Step 05: Set i = i + 1
Step 06: End
52
Problem 10 – Flow Chart
53
Problem 11 : Sum of first N integer
numbers
54
Problem 11 - IPO Chart and Algorithm
Input Processing Output
• Number N Processing Items: • Sum of first
Sum = 1 + 2 + 3 + , . . . , + N N integers
Algorithm:
Step 01: Start
Step 02: Input N from the user
Step 03: Set i = 1, sum = 0
Step 04: Repeat Step 05 to Step 06 while i <=N
Step 05: Set sum = sum + i
Step 06: Set i = i + 1
Step 07: Print sum
Step 08: End
55
Problem 11 – Flow Chart
56
Problem 12 : First N even numbers
57
Problem 12 - IPO Chart and Algorithm
Input Processing Output
• Number N Processing Items: • First N even
2N number
Algorithm:
Step 01: Start
Step 02: Input N from the user
Step 03: Set i = 1
Step 04: Repeat Step 05 to Step 06 while i <=N
Step 05: Print 2*i
Step 06: Set i = i + 1
Step 07: End
58
Problem 12 – Flow Chart
59
Problem 13 : First N multiples of 5
60
Problem 13 - IPO Chart and Algorithm
Input Processing Output
• Number N Processing Items: • First N multiples of 5
5, 10, 15, 20, 25, . . . , N*5
Algorithm:
Step 01: Start
Step 02: Input N from the user
Step 03: Set i = 1
Step 04: Repeat Step 05 to Step 06 while i <=N
Step 05: Print i * 5
Step 06: Set i = i + 1
Step 07: End
61
Problem 13 - IPO Chart and Algorithm
Input Processing Output
• Number N Processing Items: • First N multiples of 5
5, 10, 15, 20, 25, . . . , N*5
Algorithm:
Step 01: Start
Step 02: Input N from the user
Step 03: Set i = 5
Step 04: Repeat Step 05 to Step 06 while i <=N*5
Step 05: Print i
Step 06: Set i = i + 5
Step 07: End
62
Problem 13 – Flow Chart
63
Problem 13 – Flow Chart
64
Problem 14 : Factorial of a number
65
Problem 14 - IPO Chart and Algorithm
Input Processing Output
• Number N Processing Items: • Factorial of N
N! = N * (N-1) * (N-2) * , . . . , * 1
Algorithm:
Step 01: Start
Step 02: Input N from the user
Step 03: Set i = N , factorial = 1
Step 04: Repeat Step 05 to Step 06 while i >1
Step 05: Set factorial = factorial * i
Step 06: Set i = i - 1
Step 07: Print factorial
Step 08: End
66
Problem 14 – Flow Chart
67
Problem 15 : Prime or composite number
68
Problem 15 - IPO Chart and Algorithm
Input Processing Output
Algorithm:
Step 01: Start
Step 02: Input N from the user
Step 03: Set i = 2 , isPrime = true
Step 04: Repeat Step 05 to Step 06 while i < N
Step 05: if (N MOD i) = 0 then isPrime = false GOTO Step 07
Step 06: Set i = i + 1
Step 07: if isPrime = true GOTO Step 08 else GOTO Step 09
69
Problem 15 - IPO Chart and Algorithm
Input Processing Output
70
Problem 15 – Flow Chart
71