FLOWCHART
1 Pemrograman Komputer
Pertemuan 3
PROBLEM
2
PROBLEM
Pertanyaan atau tugas yang kita cari jawaban
dan/atau penyelesaiannya
Trial-and-error Scientifically"
3
THE PROBLEM-SOLVING PROCESS
Analysis
Problem specification
Design
Algorithm
Implementation
Program
Compilation
Executable (solution) 4
THE PROBLEM-SOLVING PROCESS
“Doctor, my head hurts“
Analysis
Patient has elevated pressure in
anterior parietal lobe
Problem specification
11
ALMOND AND HONEY Preheat oven for 200° C
SLICE Line a 30 cm 20 cm baking
tray with baking paper,
1/2 quantity Shortcrust and then with pastry
Pastry Bake blind for 20 minutes,
185 g unsalted butter then remove weights and
100 g castor sugar foil
5 tablespoons honey Turn oven up to 220° C.
50 ml cream Bring remaining ingredients
50 ml brandy or any to a boil, stirring.
other liqueur or spirit Spread evenly over pastry.
300 g flaked almonds Bake until topping is
bubbling and has
caramelised evenly, about
From: Stephanie Alexander, The Cook’s
Companion, Viking/Penguin, Ringwood, 15 minutes.
Victoria, 1996, p. 349.
Cool before cutting into 12
fingers or squares.
ALMOND AND HONEY Preheat oven for 200° C
SLICE Line a 30 cm 20 cm baking
tray with baking paper,
1/2 quantity Shortcrust and then with pastry
Pastry Bake blind for 20 minutes,
185 g unsalted butter then remove weights and
100 gInstructions
castor sugarare given foil
5 tablespoons
in the order
honey
in which Turn oven up to 220° C.
50 mlthey are performed
cream Bring remaining ingredients
50 ml(“executed”)
brandy or any to a boil, stirring.
other liqueur or spirit Spread evenly over pastry.
300 g flaked almonds Bake until topping is
bubbling and has
caramelised evenly, about
From: Stephanie Alexander, The Cook’s
Companion, Viking/Penguin, Ringwood, 15 minutes.
Victoria, 1996, p. 349.
Cool before cutting into 13
fingers or squares.
CORRECT ALGORITHM?
Cut chicken into pieces Arrange chicken on rice,
and brown the pieces on cover casserole and
all sides in a casserole bake in a moderate
dish in hot olive oil. oven (350°F) for 20
Remove the chicken and to minutes or until the
the juices in the rice is tender.
casserole add garlic, Add beans and
onions and green artichokes during last
peppers, and sauté until 10 minutes of cooking.
onion is golden.
Add bay leaf, whole
tomatoes, and chicken
From: “Arroz Con Pollo” in The
broth. Margaret Fulton Cookbook,
14
When the broth boils add Hamlyn, Sydney, 1968.
salt, saffron and rice.
CORRECT ALGORITHM?
Cut chicken into pieces Arrange chicken on rice,
and brown the pieces on cover casserole and
all sides in a casserole bake in a moderate
dish in hot olive oil. oven (350°F) for 20
Remove the chicken and to minutes or until the
the juices in the rice is tender.
casserole add garlic, Add beans and
onions and green artichokes during last
peppers, and sauté until 10 minutes of cooking.
onion is golden.
Add bay leaf, whole
tomatoes, and chicken
From: “Arroz Con Pollo” in The
broth. Margaret Fulton Cookbook,
15
When the broth boils add Hamlyn, Sydney, 1968.
salt, saffron and rice.
CORRECT ALGORITHM?
Cut chicken into pieces Arrange chicken on rice,
and brown the pieces on cover casserole and
all sides in a casserole bake in a moderate
dish in hot olive oil. oven (350°F) for 10
minutes.
Remove the chicken and to
the juices in the Add beans and
artichokes.
casserole add garlic,
onions and green Cover, and bake for
peppers, and sauté until another 10 minutes or
onion is golden. until rice is tender.
Add bay leaf, whole
tomatoes, and chicken
broth.
16
When the broth boils add
salt, saffron and rice.
CORRECT ALGORITHM ???...
17
CORRECT ALGORITHM
18
VALUES
Represent quantities, amounts or
measurements
May be numerical or alphabetical
(or other things)
Often have a unit related to their purpose
Example:
Recipe ingredients
19
ALMOND AND HONEY Preheat oven for 200° C
SLICE Line a 30 cm 20 cm baking
tray with baking paper,
1/2 quantity Shortcrust and then with pastry
Pastry
185 g unsalted butter Bake blind for 20 minutes,
then remove weights and
100 g castor sugar foil
5 tablespoons honey
Turn oven up to 220° C.
50 ml cream
Bring remaining ingredients
50 ml brandy or any
other liqueur or spirit to a boil, stirring.
300 g flaked almonds Spread evenly over pastry.
Bake until topping is
bubbling and has
caramelised evenly, about
From: Stephanie Alexander, The Cook’s
Companion, Viking/Penguin, Ringwood, 15 minutes.
Victoria, 1996, p. 349.
Cool before cutting into 20
fingers or squares.
ALMOND AND HONEY Preheat oven for 200° C
SLICE Line a 30 cm 20 cm baking
tray with baking paper,
1/2 quantity Shotcrust and then with pastry
Pastry Bake blind for 20 minutes,
185 g unsalted butter then remove weights and
100 g castor sugar foil
5 tablespoons honey Turn oven up to 220° C.
50 ml cream Bring remaining ingredients
50 ml brandy or any to a boil, stirring.
other liqueur or spirit Spread evenly over pastry.
300 g flaked almonds Bake until topping is
bubbling and has
caramelised evenly, about
From: Stephanie Alexander, The Cook’s
Companion, Viking/Penguin, Ringwood, 15 minutes.
Victoria, 1996, p. 349.
Cool before cutting into 21
fingers or squares.
VARIABLES
Arecontainers for values – places to store
values
Example:
Variable Values
This jar
10 cookies
23
INSTRUCTIONS (PRIMITIVES)
24
INSTRUCTIONS – EXAMPLES
Take off your shoes
Count to 10
Knit 1
Directions to perform
specific actions on values
Purl 2
and variables
Pull rip-cord firmly
25
INSTRUCTIONS -- APPLICATION
Some instructions can only be applied to a
specific type of values or variables
Examples:
26
INSTRUCTIONS (PRIMITIVES) --
RECOMMENDATIONS
When writing an algorithm, make each
instruction simple and unambiguous
Example:
Drive_To_Uni
29
FUNCTION -- EXAMPLE
function Drive_To_Uni
{
1. find car keys ...etc...etc...etc...
2. disable car alarm 52. find parking space
3. open car door 53. pull into parking
4. get in car space
5. shut car door 54. turn off engine
6. put keys in ignition 55. remove keys from
7. start car ignition
56. open car door
8. back car out of
driveway 57. get out
9. drive to end of street 58. shut car door
10. turn right 59. lock car door
11. drive to end of street 60. enable alarm
}
12. turn left
30
...etc...etc...etc
FUNCTION – EXAMPLE
32
STRUKTUR DASAR ALGORITMA
Struktur Urut
(Sequence),
Struktur Pemilihan
(Selection),
Struktur Pengulangan
(Repetition). 33
SEQUENCE
A series of instructions
...to be carried out one after the
other...
...without hesitation or question
Example:
36
SELECTION
An instruction that decides which of two
possible sequences is executed
The decision is based on a single true/false
condition
Examples:
Car repair
Reciprocals
37
SELECTION EXAMPLE – CAR REPAIR
if (motor turns)
then
{
CheckFuel
CheckSparkPlugs
CheckCarburettor
}
else
{
CheckDistributor
CheckIgnitionCoil 38
}
SELECTION EXAMPLE – CAR REPAIR
if (motor turns)
then
{
Should be a
CheckFuel true or false
CheckSparkPlugs
CheckCarburettor
condition
}
else
{
CheckDistributor
CheckIgnitionCoil
} 39
SELECTION EXAMPLE – CAR REPAIR
if (motor turns)
then
{
CheckFuel
CheckSparkPlugs
Sequence if
CheckCarburettor the condition
} is true
else
{
CheckDistributor
CheckIgnitionCoil
} 40
SELECTION EXAMPLE – CAR REPAIR
if (motor turns)
then
{
CheckFuel
CheckSparkPlugs
CheckCarburettor Sequence if the
}
else condition is
{ false
CheckDistributor
CheckIgnitionCoil
} 41
STRUKTUR PEMILIHAN (SELECTION),
Menghasilkan nilai benar (true) atau nilai salah
(false).
IF sederhana
IF <syarat> THEN
<instruksi>
<instruksi2>
ELSE IF <syarat3> THEN
<instruksi3>
ELSE IF <syaratm> THEN
<instruksim>
ELSE
<Instruksin> 44
REPETITION
Repeat an instruction...
...while (or maybe until) some true
or false condition occurs
Test the condition each time before
repeating the instruction
Also known as iteration or loop
Example:
45
REPETITION – EXAMPLE
function AskOnDate ( name, time, location )
{
Phone(name)
Say("Hey", name, "it's your lucky day!")
Say("Wanna come to", location, "at", time, "?")
ListenToReply ( )
start begging count at zero
while (reply is "No" and begging count < 100)
{
Say("Oh please!")
add 1 to begging count
ListenToReply ( )
46
}
}
REPETITION – EXAMPLE (CONT)
function AskOnDate ( name, time, location )
{
Phone(name)
Say("Hey", name, "it's your lucky day!")
Say("Wanna come to", location, "at", time, "?")
ListenToReply ( )
start begging count at zero
while ( reply is "No" and begging count < 100 )
{
Say("Oh please!")
add 1 to begging count Condition is tested
ListenToReply ( ) before sequence
}
}
47
REPETITION – EXAMPLE (CONT)
function AskOnDate ( name, time, location )
{
Phone(name)
Say("Hey", name, "it's your lucky day!")
Say("Wanna come to", location, "at", time, "?")
ListenToReply ( )
start begging count at zero
while (reply is "No" and begging count < 100)
{
Say("Oh please!")
add 1 to begging count
Sequence may not
ListenToReply ( ) get executed at all
} 48
}
REPETITION – EXAMPLE (CONT)
function AskOnDate ( name, time, location )
{
Ensure initial
Phone(name) values of variables
Say("Hey", name, "it's your lucky day!")
used in the
Say("Wanna come to", location, "at", time, "?")
ListenToReply ( )
conditions are set
start begging count at zero correctly
while (reply is "No" and begging count < 100)
{
Say("Oh please!")
add 1 to begging count
ListenToReply ( )
}
} 49
REPETITION – EXAMPLE (CONT)
function AskOnDate ( name, time, location )
{
Phone(name)
Say("Hey", name, "it's your lucky day!")
Say("Wanna come to", location, "at", time, "?")
ListenToReply ( )
start begging count at zero
while (reply is "No" and begging count < 100)
{
Say("Oh please!")
add 1 to begging count Ensure the variables
ListenToReply ( ) used in the conditions
} are updated in each 50
} repetition
REPETITION – EXAMPLE (CONT)
• What if we don’t increment the begging count?
function AskOnDate ( name, time, location )
{
Phone(name)
Say("Hey", name, "it's your lucky day!")
Say("Wanna come to", location, "at", time, "?")
ListenToReply ( )
start begging count at zero
while (reply is "No" and begging count < 100)
{
Say("Oh please!")
} Infinite loop 51
}
STRUKTUR PENGULANGAN REPETITION
Struktur for
Mengulang satu baris
instruksi atau satu blok
instruksi sampai jumlah
perulangan yang
disyaratkan terpenuhi.
Ciri utama terdapat
nilai awal dan nilai
akhir yang
menunjukkan
banyaknya pengulangan
yang akan dilakukan.
52
53
STRUKTUR WHILE
untuk mengulang satu baris
instruksi atau satu blok baris
instruksi selama syarat yang
diberikan masih terpenuhi.
Syarat akan diuji didepan.
Example:
Getting a date (again)
56
DOCUMENTATION -- EXAMPLE
Think of something romantic to do
decide on time and location
Program 58
THE SOFTWARE DEVELOPMENT PROCESS
Define the problem clearly
Analyse the problem thoroughly
59
TOP-DOWN ALGORITHM DESIGN
Write down what you have to do
Break that into 3-7 smaller steps
Break each step into 3-7 smaller
steps
Keeping subdividing until each
individual step is easy enough to do
Example:
Learning
60
TOP-DOWN DESIGN -- EXAMPLE
Read lecture notes
Read
Read textbook
Make notes
Prepare Prepare questions
Read exercise
Attend lecture
Design algorithm
Learn Listen and think
Study Complete prac
Code solution
Test and document
Attend tute
Record insights
Record answers to
Reinforce questions
Revise notes
61
CARA PENYAJIAN ALGORITMA
Uraian Deskriptif
Menggunakan bahasa yang bisa di gunakan
sehari-hari
Menggunakan flow chart (diagram
alir)
Menggunakan pseudo-code
Ditulis dalam kode-kode yang disepakati yang
mempunyai arti
62
FLOWCHART
63
ALGORITMA DAN FLOWCHART
Algoritma merupakan urutan langkah
logika pemikiran detail yang diperlukan
untuk memecahkan masalah.
Algoritma dapat direpresentasikan dalam
format grafis yang disebut flowchart
atau diagram alir.
Flowchart juga dapat digunakan untuk
menggambarkan aliran urutan program
64
BAGAN-BAGAN FLOWCHART
Terminal
Bentuk : rounded rectangle
Mengindikasikan titik awal atau akhir
65
BAGAN-BAGAN FLOWCHART
Connector
Bentuk : circle
Mengindikasikan titik penghubung ke bagan
lain yang terputus dalam satu halaman
karena terlalu jauh atau memungkinkan
memotong garis panah lain
66
BAGAN-BAGAN FLOWCHART
Connector
Bentuk : pentagon
Mengindikasikan titik penghubung ke bagan
lain yang terputus karena beda halaman
67
BAGAN-BAGAN FLOWCHART
Preparation atau initialization
Bentuk : hexagon
Mengindikasikan tahap awal pemrograman
(misalnya mendeklarasikan variabel,
mengidentifikasikan nilai awal konstanta atau
variabel)
68
BAGAN-BAGAN FLOWCHART
Data
Bentuk : parallelogram
Mengindikasikan masukan atau
keluaran data
69
BAGAN-BAGAN FLOWCHART
Process
Bentuk : rectangle
Mengindikasikan proses komputasi
70
BAGAN-BAGAN FLOWCHART
Predefined/Nested Process (Subroutine)
Bentuk : rectangle
Mengindikasikan proses komputasi
71
BAGAN-BAGAN FLOWCHART
Manual Operation
Bentuk : trapezoid
Mengindikasikan operasi yang dilakukan
secara manual
72
BAGAN-BAGAN FLOWCHART
Manual Input
Bentuk : trapezoid
Mengindikasikan masukan manual
menggunakan input device (misalnya
keyboard, mouse, bar code reader, imaging
device)
73
BAGAN-BAGAN FLOWCHART
Card
Bentuk : chamfered rectangle
Mengindikasikan penggunaan card reader
(misalnya punched card reader ataupun
memory card reader)
74
BAGAN-BAGAN FLOWCHART
Database atau Repository
Bentuk : drum
Mengindikasikan penggunaan media
penyimpanan basisdata
75
BAGAN-BAGAN FLOWCHART
Display
Bentuk : CRT Symbol
Mengindikasikan proses penampilan informasi
untuk dibaca atau dilihat user di layar
monitor atau projector
76
BAGAN-BAGAN FLOWCHART
Report
Bentuk : Sheet
Mengindikasikan proses pencetakan laporan
untuk dibaca atau dilihat user menggunakan
printer atau plotter
77
BAGAN-BAGAN FLOWCHART
Annotation
Bentuk : Arrow
Mengindikasikan hubungan presedensi antar
operasi atau alur urutan operasi
78
BAGAN-BAGAN FLOWCHART
Decision
Bentuk : diamond
Mengindikasikan pencabangan alternatif
operasi dengan pengambilan keputusan
berdasarkan kriteria atau kondisi
79
DECISION / CONDITION STRUCTURE
NO NO NO
YES
80
REPETITION / RECURSIVE STRUCTURE
YES
NO
NO
YES
81
METODOLOGI PENGEMBANGAN PROGRAM
Mulai Compile
Struktur Machine Code Keluaran
Logika Program
Sesuai ? Sesuai ?
Analisis Domain
Masalah
Compile
Berhasil
Merumuskan Verify ? Eksekusi
Algoritma Program Code Program
Debug Eksekusi
Semua Listing Program Program Selesai
Skenario
Tertulis ?
Identifier, Eksekusi
Syntax, Berhasil
Semantic ? ?
Mapping
Flowchart
82
TUGAS
Buat algoritma:
Menghitung volume tabung
Menampilkan segitiga angka sampai angka ke - n
1
22
333
nn…..n (sebanyak n)
Tampilkan algoritma di atas dalam bentuk
deskriptif dan flowchart
Buat contoh running-nya
83