Oct
21
2015
0

Review Algorithm sesi 3

Di pertemuan ke-3 algoritma & pemrograman kali ini, saya belajar tentang selection dan error types.

Selection adalah sekumpulan instruksi atau satu instruksi dapat dijalankan atau tidak dengan kondisi yang telah ditentukan.

  • Selection mempunyai 4 jenis: If, If-else, switch-case, ?: operator
  • If

Contoh penggunaan IF:

Syntax :

1. if (boolean expression) statement;

or

2. if (boolean expression) {

     statement1;

     statement2;             Block of statements

  ……

}

Jika boolean expression menghasilkan True, maka blok statement 1 yang akan digunakan, jika False, blok statement 2 yang digunakan.

Flow chart:

berikut ini adalah flowchart IF statement

Flowchart IF

  • If-else

Contoh penggunaan If-else

Syntax

if (boolean expression) statement1;

else statement2;

or

if(boolean expression)        <

statement 1;                           <       Block statement 1

statement 2;                           <

………

}

else {

statement 3;               <    Block statement 2

statement 4;               <

….

}

Jika boolean expression menghasilkan True, maka blok statement 1 akan dijalankan, jika False, blok statement 2 akan dijalankan

  • Switch-case

Statement ini digunakan sebagai pengganti if-else, saat jumlah tingkat if-else nested besar dan sulit dibaca.

Contoh penggunaan switch-case:

Syntax:

switch (expression) {

  case constant1 : statements1; break;

  .

  .

  case constant2 : statements2; break;

  default : statements;

}

Nilai statement switch meng-evaluasikan expression dengan melihat setiap case constant value. Jika nilai expression sama dengan case constant value, maka statement terkait akan dijalankan. Jika tidak ada yang sama, statement default yang dijalankan.

  • ?: Operator

Fungsinya mirip dengan statement IF, bedanya ini mengembalikan nilai.

Syntax:

condition ? then-expression : else-expression

  • Go to & Label

C masih mendukung cara lama, yaitu go to statement

Syntax:

goto label;

……

label :

……

 

  • Error types

Tipe2 error ada 4 macam, yaitu

 Compile-Time error

Error yang terjadi saat compiling program, compile error dapat dibagi menjadi 2

  1.   Syntax error
  2.   Semantic error

– Link-time error

Sukses disusun, tetapi menyebabkan link error, disebabkan oleh tidak ada kode object di link time.

– Run-time error

Terjadi saat eksekusi program c dan biasanya terjadi karena beberapa operasi illegal yang dilakukan oleh program.

contoh operasi illegal yang dapat menghasilkan runtime error adalah:

  • Dividing a number by zero
  • Trying to open a file which is not created
  • Lack of free memory space

– Logical error

Adalah error yang terjadi pada output program, keberadaan logical error dapat mengarah pada output yang salah atau yang tidak diinginkan dan disebabkan oleh error di logic yang teraplikasikan di program untuk menghasilkan output yang diinginkan

Logical error tidak dapat terdeteksi oleh compiler, dan dengan demikian, programmer harus mengecek coding keseluruhan baris demi baris.

Written by zedmatter123 in: College assignment |
Oct
14
2015
0

Review Algorithm – Sesi #2

Berikut ini adalah review mata kuliah Algoritma & Pemrograman pada tanggal 08 Oktober 2015, Ruang 800

Operator adalah simbol yang memproses nilai untuk menghasilkan nilai baru

Operand adalah data yang dapat dimanipulasi atau dioperasikan

Example:

C=A + B

(= dan tanda +  adalah operator, A, B ,C adalah operand)

Operand dapat dibagi menjadi 3 berdasarkan jumlah angkanya

  • Unary operand (Unary membutuhkan 1 operand)
  • Binary operand (Binary membutuhkan 2 operand)
  • Trinary operand (Trinary membutuhkan 3 operand)

Berdasarkan tipe operasinya, operator dapat dikategorikan sebagai berikut:

  • Assignment operator (‘=’ adalah operator yang digunakan untuk assignment)
  • Logical operator
  • Arithmetic operator (proses matematika yang digunakan dalam C, contohnya adalah subtraksi

subtraksi mengambil nilai sebanyak nilai disebelahnya, contoh: 15-4 = 11)

Symbol Functionality Example
+ Addition x = y + 6;
Subtraction y = x – 5;
* Multiply y = y * 3;
/ Division z = x/y;
% Modulo A = 10 % 3;
++ Increment x++;
Decrement z–;
() Scope / Priority x=(2+3)*5

contoh fungsi-fungsi dalam arithmetic operator

  • Relational operator (digunakan untuk menguji true atau false sebuah data)

 

Symbol Functionality
= = Equality
!= Not equal
< Less than
> Greater than
<= Less or equal than
>= Greater or equal than
?: Conditional assignment

Simbol yang digunakan dalam relational operator

  • Bitwise operator
  • Pointer operator

Thank you

Written by zedmatter123 in: College assignment |
Oct
06
2015
0

Review Algorithm learning session 1 – 1 Oktober 2015

OOP: Object Oriented Programming

various kinds of OOPs

  • Inheritance : Allows classes or object to be inherited from other classes/object in the same way, this allows the use of code reusability, thus specifying implementation to maintain same behaviour, just like father and son.
  • Encapsulation: Is a packing of data into a single object, creating a digital “capsule” that protects it from outside sources thus allows it to be protected from accidental corruption or malicious programs
  • Abstract: Type of OOPs that is random, which allows it to correct itself, but also unstable.

Programming language difficulty levels

  • Low-level programming language : Assembler
  • Medium-level programming language : C, Pascal, Fortran
  • High-level programming language : C#, Java, C++

Basic forms of algorithm can be described in two ways:

  • Pseudocode
  • Flowchart

Pseudocode

Pseudocode is an informal description for high-level programming language of a computer program or algorithm, it describes the algorithm intended for human reading, instead of machine reading.

Example:

Start

Wake up

Walks out from the bed

Opens the bedroom door

Walks out from the bedroom door

Sit on a couch

Watch TV

End

Flowchart

Flowchart is used to simplify reading of pseudocode for an algorithm, instead of texts, it uses visual information in a form of two-dimensional bubbles, like baloon chat in comics, that interconnected to each other with lines, the process “flows” from one bubbles to the next, forming the algorithm and detailing it for human understanding.

Example:

Algorithm - Flowchart

 

Flowchart types

Algorithm - Flowchart 2

Example of efficient use of algorithms

  • Correct
  • Fast
  • Small space
  • Clever
  • General
  • Simple

Good Algorithm Practice

  • Having the right logical flow to solve the problem
  • Producing the correct output in a time efficient manner
  • Written using unambiguous structured language
  • Easy implementation into real programming language
  • All steps and operations are clearly defined and ended

Founder of C 

  • Dennis Ritchie

Dennis Ritchie founded C programming language between 1969 to 1973 at AT&T Bell Labs

Why do we use C?

  • Flexible
  • Compatibility
  • Ease of use
  • Simplicity

History of Algorithm

Al-Khawarizmi

Algorithm is created by an arabic man named Al-Khawarizmi (Abu Jafar Muhammad Ibnu Musa Al Khawarizmi). He is a medieval arabic mathematician, algorithm is created to solve problems in a methodical way, thus creating computers of today and change the face of the modern world as we know it.

 

 

The End.

Thank you.

Written by zedmatter123 in: College assignment |

Powered by WordPress. Theme: TheBuckmaker. Zinsen, Streaming Audio