4 - Intro To Problem Solving - Flowchart Pseudocode
4 - Intro To Problem Solving - Flowchart Pseudocode
4 - Intro To Problem Solving - Flowchart Pseudocode
STRUCTURED
ALGORITHM &
PROGRAMMING
INTRODUCTION TO PROBLEM SOLVING
FLOWCHART
LEARNING OUTCOME
By the end of this chapter, you will be able
to:
+ List the component in problem solving
+ Define algorithm
+ Differentiate between pseudocode and flowchart
+ Solve a given problem by applying flowchart
+ Compare and contrast control structures with its
flowchart
+ Solve a given problem by applying pseudocode
technique
+ Perform desk-checking 2
PROBLEM SOLVING
• Understand and analyze the problem
• Includes 3 components:
3
PROBLEM SOLVING
A café needs a computerized program to find its weekly
profitable menu. The worker should key in data that
includes menu name, quantity sold and its price. Then, the
program should be able to calculate the total sale for each
menu ordered by the customer. If the total sale of the
menu is more than RM500, then the café is making profit
from the menu and shall continue to have it in the menu
list. The program should display the menu name that is
profitable and also the menu that is to be discontinued.
PROBLEM SOLVING
8
..ALGORITHM
Can be implemented by using either:
OR
PSEUDOCODE FLOWCHART
9
FLOWCHART
Symbol Purpose
Terminal Flowchart should always begin and
end with this symbol. It indicates the
starting or ending point of the logic.
Input / Output It symbolizes input (Read / Prompt /
Get) or output (Print / Write / Put /
Output / Display) process in a code.
FLOWCHART SYMBOLS
Symbol Purpose
Process Symbolizes any process in an
algorithm. Example of processes:
Declare variables, perform
calculations and assign values to
variables.
Predefined Indicates a module in an algorithm.
process In other words, the module can be
expended to include few sub
processes.
FLOWCHART SYMBOLS
Symbol Purpose
to be use when there are decisions to
Decision be made in the logic. There will be
options where the logic needs to
decide which path to take (either true
or false).
SEQUENTIAL
SELECTION
REPETITION
1. SEQUENTIAL
Any other
possible ways??
1. SEQUENTIAL
How to add 2 numbers START
by using a computer
program? Declare variables
Find the IPO.. num_1,num_2,total
1. Start
Get num_1,num_2
2. Declare variables, num_1,
num_2, total
total=num_1+num_2
3. Get num_1 + num_2
4. total = num_1 + num_2 Display total
5. Display total
END
6. End
1. SEQUENTIAL
Draw a flow chart for a computer program that will get two
test results from the user, calculate the average of the test
results and display the calculation result .
2. SELECTION
• Condition:
• based on the condition criteria, certain actions will be
executed, and some will not
• Condition can either be:
• true or false
• yes or no
• We could also have multiple conditions/ options
2. SELECTION
• How to have decision/ selection in flowchart?
End
26
3. REPETITION
3
0
PSEUDOCODE?
✕ Really structured English that has been
formalized and abbreviated to look like the high-
level computer languages.
1. Start
2. Declare variables-width, length, size
3. Prompt user for width, length
4. Get width, length Remember!!!!!
5. size = width * length Another programmer will need
6. Display size to understand the set of
instructions you write.
7. End So, meaningful words &
phrases will make it easier
to translate pseudocode to
programming language later.
31
PSEUDOCODE
MEANINGFUL NAMES
✕ Meaningful names should be used to represent
variables in our pseudocode/flowchart
✕ number1 vs n1<-use meaningful naming
✕ majority of programming languages does not
allow gap (space) in variable names
Eg. Total Sales X
THE STRUCTURE
+ PROCESSES?
+ A list of actions needed to produce
the required outputs.
+ OUTPUT?
+ A list of the outputs required. 34
PSEUDOCODE
✕ A computer can:
+ receive information To be discussed in this
+ put out information chapter
✕ ‘Read’:
use to indicate that input will be
retrieve from record in file.
37
PSEUDOCODE
38
COMPUTER
CAN PUT OUT
INFORMATION
17
PSEUDOCODE
Problem
You need to write pseudocode for a program that
will add up two numbers
5. Display total
6. End.
45
YOUR TURN….
✕ INPUT: ???
✕ PROCESS: ???
✕ OUTPUT: ?
24
STEP 1. Identify the Input, Process &
Output
1 2 3
INPUT: PROCESS: OUTPUT:
declare variables,
number1, multiplication result
get three numbers,
number2, multiply all numbers,
number3 display multiplication
result
STEP 2. Write pseudocode.
1. Start
2. Declare variables, number1,
number2,number3, result
3. Prompt and Get number1,
number2,number3
4. result = number1 * number2 * number3
5. Display result
6. End.
start
TotalStudent< No
492
Yes Yes
CAN YOU WRITE THE Prompt & Get StudentName,
PSEUDOCODE FOR ExamScore
THIS FLOW CHART?
Calculate Avg=TotalExamScore/
TotalStudent
Increase TotalStudent
Calculate
TotalExamScore=TotalExamScore
+ExamScore
Print AverageScore
end
DESK CHECKING
28
DESK CHECKING
✕ Should have at least 2 sets of input data for
testing.
✕ Write the desired outcome from each set
31
MORE
EXAMPLES
32
YOUR TURN..
Write a pseudocode for a program that
requires three numbers from the user. The
program shall add all three numbers and
display the result. Perform the desk check for
the program with 2 pass.
INPUT: ???
PROCESS: ???
OUTPUT: ?
33
YOUR TURN (AGAIN…)
Complete the pseudocode and the desk check for a
program that will calculate a land price based on the width
and length of the land (keyed- in by the user).
1. Start
2. Declare variables, width, length, size, price
3. Prompt user for
4. Get
5. size =
6. price = * 5.40
7. Display
8. End
56
SUMMARY
57