CHAPTER 13 COMPUTER PROGRAMMING SOFTWARE DEVELOPMENT
Discovering Computers
CHAPTER 13
COMPUTER PROGRAMMING
& SOFTWARE DEVELOPMENT
Chapter 13 Objectives
Differentiate between machine ,
assembly languages, high-level languages
Describe various ways to develop Web pages
including HTML, scripting languages, XHTML,
XML, WML, and Web page authoring software
Identify and discuss the purpose of
procedural programming languages
Identify the uses of popular multimedia
authoring programs
Discuss the advantages and uses of
visual programming languages
List the 6 steps in the program development cycle
Id tif and
Identify
d di
discuss th
the characteristics
h
t i ti off
object-oriented programming languages
Diff
Differentiate
ti t between
b t
structured
t t dd
design
i and
d
object-oriented design
Identify the uses of various nonprocedural
languages and tools
Explain the basic control structures used in
designing solutions to programming problems
1
Program Komputer & Bahasa Pemrograman
Program Komputer
Sekumpulan instruksi yang membuat komputer
dapat menampilkan suatu tugas tertentu
Bahasa Pemrograman: Menyajikan sintax, aturan
kode instruksi yang dibutuhkan pada sebuah program
komputer
Computer Programs & Programming Languages
low-level languages dan high-level languages
Low-level
language
Machine-dependent
runs only on one type of computer
Machine and assembly languages
are low-level
High-level
language
Often machine-independent
can run on many different
types of computers
2
Low-Level Languages: Machine
Bahasa mesin
Bahasa yang dapat
langsung dikenali
komputer
Menggunakan binary digits
(1 dan 0) dengan
kombinasi huruf dan angka
yang merepresentasikan
binary digits
Low-Level Languages: Assembly
Bahasa rakitan
(assembly language)
Instruksi yang berupa
singkatan dan kode yang
memiliki arti khusus
Source program berupa
kode untuk dikonfersikan
ke bahasa mesin
3
Bahasa Level Tinggi
Procedural Languages:
BASIC, BASICA, GWBASIC, QBASIC
COBOL
FORTRAN
PASCAL
Object Oriented Languages
JAVA
Object Oriented
C++
Object Oriented
SMALLTALK
Object Oriented
Alice (game programming) Object Oriented
(based on Java)
VISUAL BASIC .NET Object Based
The Program Development Cycle: 6 Steps
Siklus membangun program
Langkah-langkah yang dilakukan programmer dalam
membangun program
Programming
team—Beberapa
programer yang
membuat
program
The Program
g
Development
Cycle is Step 4 in
the System
Development
Life Cycle
(SDLC)
4
Step 1 — Analisa Kebutuhan
Yang termasuk kegiatan menganalisa kebutuhan?
1.
2
2.
3.
Mereview kebutuhan
Bertemu sistem analis dan pengguna
Mengidentifikasi input, output, pemrosesan dan
komponen data
IPO chart
IPO chart—
Mengidentifikasi
input program,
outputs dan step
outputs,
pemrosesan
Step 2 — Design the Solution
Apa saja yang termasuk dalam perancangan solusi?
Two
approaches
Devise
solution
algorithm,,
algorithm
step--by
step
by--step
procedure to
solve problem
Obj t-oriented
i t d
ObjectObject
design
Structured
design, sometimes
design,
called top
top--down design
Programmer
begins with general
design and moves toward
detailed design
5
Step 2 — Design the Solution
hierarchy chart
Menampilkan modul program secara grafis &
relasinya
Disebut juga Structure Chart atau VTOC: Visual Table
of Contents
Step 2 — Design the Solution
Object-oriented design (OOD)
Programmer mengemas data dan
metode (procedures) dalam unit
tunggal, disebut object
Objek dikelompokkan menjadi kelaskelas
A Class Diagram secara grafis
merepresentasikan hubungan hirarkis
antar kelas
6
Step 3 — Validasi Desain
Apa saja yang termasuk dalam validasi desain?
Check
Ch
k program
design for accuracy
Desk check
programmers use test
data to step through logic
Test data
sample data that
mimics real data that
program will process
Programmer checks
l i for
logic
f correctness
t
and attempts to uncover
logic errors
Logic error
design flaw
that causes
inaccurate results
Structured walkthrough
programmer explains
logic of algorithm while
programming team steps
through program logic
Next
p. 13.32
Step 4 — Implement the Design
Implementation? (Coding,testing,debugging)
Menulis kode yang diterjemahkan dari desain ke program
Syntax—aturan yang menspesifikkan bagaimana untuk menulis
instruksi
Comments—dokumentasi program
Extreme Programming (XP)—coding dan segera setelah
persyaratan ditetapkan
7
Step 5 — Test the Solution
Apa saja yang termasuk dalam pengujian solusi?
Ensure program runs correctly
and is error free
Alpha & Beta testing:
What is the difference ?
Debugging—
Debugging
—locating and
correcting syntax and logic
errors, or bugs
Test copy of program,
called beta
beta,, sometimes
used to find bugs
Step 6 — Document the Solution
Apa saja yang termasuk dalam dokumentasi solusi?
Programer melakukan dua aktivitas
Mereview kode
program—
menghilangkan dead
code yaitu program
instruksi yang tidak
pernah dieksekusi
Mereview
dokumentasi
8
Algoritma
Algorithm: langkah-langkah prosedur
untuk menyelesaikan masalah.
Masalah yang diselesaikan TIDAK harus
berupa program komputer
Prosedur untuk mengganti ban mobil yang
kempes juga merupakan algoritma,
prosedur untuk merakit sepeda
sepeda, membuat
kue, atau membangun rumah
Coding Computer Programs
Apa saja yang termasuk pengkodean program?
Two steps:
1
1.
Menterjemahkan solusi
algoritma ke dalam bahasa
pemrograman
2. Memasukkan kode bahasa
pemrograman ke dalam komputer
Setiap bahasa pemrograman memiliki
sintax yang spesifik
Syntax
Sekumpulan grammar
dan aturan yang
menspesifikan
bagaimana menulis
instruksi untuk suatu
algoritma solusi
Next
p.15.13
9
Testing Programs and Run time Errors
Run time error
Kegagalan program yang terjadi
ketika program dieksekusi.
Programmer menggunakan data
(good, bad, none) dengan senaja
menyebabkan run time error
untuk menguji program.
Contoh run time errors:
Input file not found
Division by zero
Array Index out of bounds
Buffer
B ff overflow
fl General
G
l
Protection Fault (GPF)
(Memory overrun)
Dividing a Number by Zero
G = 1234.56 / .00000000000000000001
(Di i
(Divisor
approaches
h zero 0 )
(Then, invert and multiply)
Example: x = a / 1/b = ab
g number))
G = 1234.56 x 10 ** 320 ((G is a veryy large
Jika terlalu besar, akan memenuhi register
datanya.
Infinity symbol
10
Debugging Computer Programs
Debugging
Proses mengkoreksi
sintax dan eror
logika dalam
program
Error berarti bug
Kata bug pertama kali
dikenal dalam
bahasa
pemrograman
COBOL (1959)
Debug Utilities
Debug utility
Software Computer: debugger
Tersedia dengan
g banyak
y
kompiler
Memungkinkan mengidentifikasi
kesalahan sintax dan
menemukan kesalahan logika
Programmer can menguji nikai
keluaran program saat
program berjalan slow
motion
Mill
i
B
Millennium
Bug
Also called the Y2K
bug
Took effect when the
computer date rolled
over to January 1,
2000
Non Y2K compliant
computers read the
date as 01/01/00
Next
p.15.14
11
Y2K Computation (Example of error)
currentYear = 00; // Using a 2-digit value for year
yearOfBirth = 1990;
Age = currentYear – yearOfBirth;
Age = 0 – 1990
Age = -1990
// Ridiculous value for Age !
currentYear = 2011; // Correct 4-digit
4 digit year
Age = 2011 – 1990
Age = 21
// Correct age
http://www.y2ktimebomb.com/
Year 2038
Unix Y2K Bug
http://en.wikipedia.org/wiki/Year_2038_problem
The year 2038 problem (also known as the Unix Millennium
Bug, Y2K38, Y2.038K, or S2G by analogy to the Y2K
problem)
The problem affects all software and systems that both store
system time as a signed 32-bit integer, and interpret this
number as the number of seconds since 00:00:00 UTC on
Thursday, 1 January 1970.
Times beyond this moment will "wrap
wrap around"
around and be
stored internally as a negative number, which these systems
will interpret as a date in 1901 rather than 2038.
12
Y2K Problem Examples
Visit: http://en.wikipedia.org/wiki/Y2K
In the C programming language, the standard library function
to get the current year originally did have the problem that it
returned
t
d only
l th
the year number
b within
ithi th
the 20th century,
t
and
d ffor
compatibility's sake still returns the year as year minus 1900.
Many programmers in C, and in Perl and Java, two
programming languages widely used in Web development that
use the C functions, incorrectly treated this value as the last two
digits of the year. On the Web this was a mostly harmless bug,
but it did cause many dynamically generated webpages to
display January 1, 2000, as "1/1/19100", "1/1/100", or variations
of that depending on the format.
Division Computation (Example of error)
int num1 = 167;
int num2 = 0;
i t result;
int
lt
if (num2 != 0)
result = num1 / num2;
else
// Divide num1 by num2
num2 = 1;
result = num1 / num2;
print ((“Error:Attempt
Error:Attempt to Divide by zero
zero”);
);
// Causes program to crash
// Cannot divide by zero
13
Designing Computer Programs
Top-down design
Memecah spesifikasi satu
program ke dalam
bagian yang lebih mudah
dikelola
Hal ini disebut module
Mengidentifikasi fungsi utama
program, yaitu main routine atau main
program
module
Decompose (break down) main routine ke dalam
sections yang lebih kecil subroutines
Analisa tiap subroutine untuk menentukan
apakah dapat di dekomposi lagi
Melanjutkan mendekomposisi subroutines sampai
maing-masing menampilkan fungsi tunggal
Bagian dari program yang melakukan fungsi
tunggal adalah modul
Structured Computer Program Design
Desain terstruktur
Suatu teknik membangun
program dengan
mengkombinasikan 3
struktur kontrol dasar
Struktur kontrol adalah
rencangan yang menentukan
urutan logis ari instruksi
program
Masing-masing modul terdiri
dari lebih dari satu struktur
kontrol
Sequence
control
structure
Selection
control
structure
Repetition
control
structure
Next
p.15.6
14
Sequence Control Structure
Sequence control structure
Menampilkan satu atau
lebih aksi yang saling
berurutan.
Aksi:
Inputs
Processes
Outputs
Next
p.15.7 Fig. 15-5
Selection Control Structure (IF-THEN-ELSE)
Selection Control Structure
Memberitahu
program aksi
mana yang akan
diambil,
berdasarkan
kondisi tertentu
2 tipe umum struktur
selection kontrol
if-then-else
control structure
case control
structure
Next
p.15.7
15
Selection Control Structure (IF-THEN-ELSE)
IF-THEN-ELSE
Memungkinkan program untuk mengevaluasi kondisi dan
menghasilkan
h ilk 2 kemungkinan:
k
ki
t
true
atau
t false
f l
Jika hasilnya true, program
menampilkan
aksi
Jika hasilnya
salah, program
Menampilkan
aksi yang berbeda
Next
p.15.7 Fig. 15-6
Selection Control Structure (IF-THEN-ELSE)
A = 12 // Assign 12 to integer variable A
B = 65 // Assign 65 to integer variable B
IF ( A > B ) // Th
The true
t
condition,
diti
if A greater
t th
than B
PRINT “The Internet is a great source of info!”
PRINT “Have a nice day !”
ELSE
// The false condition: means A = 90) // Nested IF “ladder”
GRADE = ‘A’;
// Assign letter grade of ‘A’
ELSE
IF (SCORE >= 80)
GRADE = ‘B’;
ELSE
IF (SCORE >= 70)
GRADE = ‘C’;
ELSE
IF(SCORE >= 60)
GRADE = ‘D’;
ELSE
// Note: SCORE is
CHAPTER 13
COMPUTER PROGRAMMING
& SOFTWARE DEVELOPMENT
Chapter 13 Objectives
Differentiate between machine ,
assembly languages, high-level languages
Describe various ways to develop Web pages
including HTML, scripting languages, XHTML,
XML, WML, and Web page authoring software
Identify and discuss the purpose of
procedural programming languages
Identify the uses of popular multimedia
authoring programs
Discuss the advantages and uses of
visual programming languages
List the 6 steps in the program development cycle
Id tif and
Identify
d di
discuss th
the characteristics
h
t i ti off
object-oriented programming languages
Diff
Differentiate
ti t between
b t
structured
t t dd
design
i and
d
object-oriented design
Identify the uses of various nonprocedural
languages and tools
Explain the basic control structures used in
designing solutions to programming problems
1
Program Komputer & Bahasa Pemrograman
Program Komputer
Sekumpulan instruksi yang membuat komputer
dapat menampilkan suatu tugas tertentu
Bahasa Pemrograman: Menyajikan sintax, aturan
kode instruksi yang dibutuhkan pada sebuah program
komputer
Computer Programs & Programming Languages
low-level languages dan high-level languages
Low-level
language
Machine-dependent
runs only on one type of computer
Machine and assembly languages
are low-level
High-level
language
Often machine-independent
can run on many different
types of computers
2
Low-Level Languages: Machine
Bahasa mesin
Bahasa yang dapat
langsung dikenali
komputer
Menggunakan binary digits
(1 dan 0) dengan
kombinasi huruf dan angka
yang merepresentasikan
binary digits
Low-Level Languages: Assembly
Bahasa rakitan
(assembly language)
Instruksi yang berupa
singkatan dan kode yang
memiliki arti khusus
Source program berupa
kode untuk dikonfersikan
ke bahasa mesin
3
Bahasa Level Tinggi
Procedural Languages:
BASIC, BASICA, GWBASIC, QBASIC
COBOL
FORTRAN
PASCAL
Object Oriented Languages
JAVA
Object Oriented
C++
Object Oriented
SMALLTALK
Object Oriented
Alice (game programming) Object Oriented
(based on Java)
VISUAL BASIC .NET Object Based
The Program Development Cycle: 6 Steps
Siklus membangun program
Langkah-langkah yang dilakukan programmer dalam
membangun program
Programming
team—Beberapa
programer yang
membuat
program
The Program
g
Development
Cycle is Step 4 in
the System
Development
Life Cycle
(SDLC)
4
Step 1 — Analisa Kebutuhan
Yang termasuk kegiatan menganalisa kebutuhan?
1.
2
2.
3.
Mereview kebutuhan
Bertemu sistem analis dan pengguna
Mengidentifikasi input, output, pemrosesan dan
komponen data
IPO chart
IPO chart—
Mengidentifikasi
input program,
outputs dan step
outputs,
pemrosesan
Step 2 — Design the Solution
Apa saja yang termasuk dalam perancangan solusi?
Two
approaches
Devise
solution
algorithm,,
algorithm
step--by
step
by--step
procedure to
solve problem
Obj t-oriented
i t d
ObjectObject
design
Structured
design, sometimes
design,
called top
top--down design
Programmer
begins with general
design and moves toward
detailed design
5
Step 2 — Design the Solution
hierarchy chart
Menampilkan modul program secara grafis &
relasinya
Disebut juga Structure Chart atau VTOC: Visual Table
of Contents
Step 2 — Design the Solution
Object-oriented design (OOD)
Programmer mengemas data dan
metode (procedures) dalam unit
tunggal, disebut object
Objek dikelompokkan menjadi kelaskelas
A Class Diagram secara grafis
merepresentasikan hubungan hirarkis
antar kelas
6
Step 3 — Validasi Desain
Apa saja yang termasuk dalam validasi desain?
Check
Ch
k program
design for accuracy
Desk check
programmers use test
data to step through logic
Test data
sample data that
mimics real data that
program will process
Programmer checks
l i for
logic
f correctness
t
and attempts to uncover
logic errors
Logic error
design flaw
that causes
inaccurate results
Structured walkthrough
programmer explains
logic of algorithm while
programming team steps
through program logic
Next
p. 13.32
Step 4 — Implement the Design
Implementation? (Coding,testing,debugging)
Menulis kode yang diterjemahkan dari desain ke program
Syntax—aturan yang menspesifikkan bagaimana untuk menulis
instruksi
Comments—dokumentasi program
Extreme Programming (XP)—coding dan segera setelah
persyaratan ditetapkan
7
Step 5 — Test the Solution
Apa saja yang termasuk dalam pengujian solusi?
Ensure program runs correctly
and is error free
Alpha & Beta testing:
What is the difference ?
Debugging—
Debugging
—locating and
correcting syntax and logic
errors, or bugs
Test copy of program,
called beta
beta,, sometimes
used to find bugs
Step 6 — Document the Solution
Apa saja yang termasuk dalam dokumentasi solusi?
Programer melakukan dua aktivitas
Mereview kode
program—
menghilangkan dead
code yaitu program
instruksi yang tidak
pernah dieksekusi
Mereview
dokumentasi
8
Algoritma
Algorithm: langkah-langkah prosedur
untuk menyelesaikan masalah.
Masalah yang diselesaikan TIDAK harus
berupa program komputer
Prosedur untuk mengganti ban mobil yang
kempes juga merupakan algoritma,
prosedur untuk merakit sepeda
sepeda, membuat
kue, atau membangun rumah
Coding Computer Programs
Apa saja yang termasuk pengkodean program?
Two steps:
1
1.
Menterjemahkan solusi
algoritma ke dalam bahasa
pemrograman
2. Memasukkan kode bahasa
pemrograman ke dalam komputer
Setiap bahasa pemrograman memiliki
sintax yang spesifik
Syntax
Sekumpulan grammar
dan aturan yang
menspesifikan
bagaimana menulis
instruksi untuk suatu
algoritma solusi
Next
p.15.13
9
Testing Programs and Run time Errors
Run time error
Kegagalan program yang terjadi
ketika program dieksekusi.
Programmer menggunakan data
(good, bad, none) dengan senaja
menyebabkan run time error
untuk menguji program.
Contoh run time errors:
Input file not found
Division by zero
Array Index out of bounds
Buffer
B ff overflow
fl General
G
l
Protection Fault (GPF)
(Memory overrun)
Dividing a Number by Zero
G = 1234.56 / .00000000000000000001
(Di i
(Divisor
approaches
h zero 0 )
(Then, invert and multiply)
Example: x = a / 1/b = ab
g number))
G = 1234.56 x 10 ** 320 ((G is a veryy large
Jika terlalu besar, akan memenuhi register
datanya.
Infinity symbol
10
Debugging Computer Programs
Debugging
Proses mengkoreksi
sintax dan eror
logika dalam
program
Error berarti bug
Kata bug pertama kali
dikenal dalam
bahasa
pemrograman
COBOL (1959)
Debug Utilities
Debug utility
Software Computer: debugger
Tersedia dengan
g banyak
y
kompiler
Memungkinkan mengidentifikasi
kesalahan sintax dan
menemukan kesalahan logika
Programmer can menguji nikai
keluaran program saat
program berjalan slow
motion
Mill
i
B
Millennium
Bug
Also called the Y2K
bug
Took effect when the
computer date rolled
over to January 1,
2000
Non Y2K compliant
computers read the
date as 01/01/00
Next
p.15.14
11
Y2K Computation (Example of error)
currentYear = 00; // Using a 2-digit value for year
yearOfBirth = 1990;
Age = currentYear – yearOfBirth;
Age = 0 – 1990
Age = -1990
// Ridiculous value for Age !
currentYear = 2011; // Correct 4-digit
4 digit year
Age = 2011 – 1990
Age = 21
// Correct age
http://www.y2ktimebomb.com/
Year 2038
Unix Y2K Bug
http://en.wikipedia.org/wiki/Year_2038_problem
The year 2038 problem (also known as the Unix Millennium
Bug, Y2K38, Y2.038K, or S2G by analogy to the Y2K
problem)
The problem affects all software and systems that both store
system time as a signed 32-bit integer, and interpret this
number as the number of seconds since 00:00:00 UTC on
Thursday, 1 January 1970.
Times beyond this moment will "wrap
wrap around"
around and be
stored internally as a negative number, which these systems
will interpret as a date in 1901 rather than 2038.
12
Y2K Problem Examples
Visit: http://en.wikipedia.org/wiki/Y2K
In the C programming language, the standard library function
to get the current year originally did have the problem that it
returned
t
d only
l th
the year number
b within
ithi th
the 20th century,
t
and
d ffor
compatibility's sake still returns the year as year minus 1900.
Many programmers in C, and in Perl and Java, two
programming languages widely used in Web development that
use the C functions, incorrectly treated this value as the last two
digits of the year. On the Web this was a mostly harmless bug,
but it did cause many dynamically generated webpages to
display January 1, 2000, as "1/1/19100", "1/1/100", or variations
of that depending on the format.
Division Computation (Example of error)
int num1 = 167;
int num2 = 0;
i t result;
int
lt
if (num2 != 0)
result = num1 / num2;
else
// Divide num1 by num2
num2 = 1;
result = num1 / num2;
print ((“Error:Attempt
Error:Attempt to Divide by zero
zero”);
);
// Causes program to crash
// Cannot divide by zero
13
Designing Computer Programs
Top-down design
Memecah spesifikasi satu
program ke dalam
bagian yang lebih mudah
dikelola
Hal ini disebut module
Mengidentifikasi fungsi utama
program, yaitu main routine atau main
program
module
Decompose (break down) main routine ke dalam
sections yang lebih kecil subroutines
Analisa tiap subroutine untuk menentukan
apakah dapat di dekomposi lagi
Melanjutkan mendekomposisi subroutines sampai
maing-masing menampilkan fungsi tunggal
Bagian dari program yang melakukan fungsi
tunggal adalah modul
Structured Computer Program Design
Desain terstruktur
Suatu teknik membangun
program dengan
mengkombinasikan 3
struktur kontrol dasar
Struktur kontrol adalah
rencangan yang menentukan
urutan logis ari instruksi
program
Masing-masing modul terdiri
dari lebih dari satu struktur
kontrol
Sequence
control
structure
Selection
control
structure
Repetition
control
structure
Next
p.15.6
14
Sequence Control Structure
Sequence control structure
Menampilkan satu atau
lebih aksi yang saling
berurutan.
Aksi:
Inputs
Processes
Outputs
Next
p.15.7 Fig. 15-5
Selection Control Structure (IF-THEN-ELSE)
Selection Control Structure
Memberitahu
program aksi
mana yang akan
diambil,
berdasarkan
kondisi tertentu
2 tipe umum struktur
selection kontrol
if-then-else
control structure
case control
structure
Next
p.15.7
15
Selection Control Structure (IF-THEN-ELSE)
IF-THEN-ELSE
Memungkinkan program untuk mengevaluasi kondisi dan
menghasilkan
h ilk 2 kemungkinan:
k
ki
t
true
atau
t false
f l
Jika hasilnya true, program
menampilkan
aksi
Jika hasilnya
salah, program
Menampilkan
aksi yang berbeda
Next
p.15.7 Fig. 15-6
Selection Control Structure (IF-THEN-ELSE)
A = 12 // Assign 12 to integer variable A
B = 65 // Assign 65 to integer variable B
IF ( A > B ) // Th
The true
t
condition,
diti
if A greater
t th
than B
PRINT “The Internet is a great source of info!”
PRINT “Have a nice day !”
ELSE
// The false condition: means A = 90) // Nested IF “ladder”
GRADE = ‘A’;
// Assign letter grade of ‘A’
ELSE
IF (SCORE >= 80)
GRADE = ‘B’;
ELSE
IF (SCORE >= 70)
GRADE = ‘C’;
ELSE
IF(SCORE >= 60)
GRADE = ‘D’;
ELSE
// Note: SCORE is