P. 1
Logika Dan Algoritma, Pertemuan 2

# Logika Dan Algoritma, Pertemuan 2

|Views: 143|Likes:

Published by: defra_oi on Jan 04, 2011

### Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PPT, PDF, TXT or read online from Scribd
See more
See less

02/25/2013

pdf

text

original

# The 2nd Subject

Logical Operations 2-branch Conditional Structures Many-branch Conditional Structures

LOGICS AND ALGORITHMS
by: Joz

BOOLEAN TYPES

0
FALSE NO

1
TRUE YES

LOGICAL OPERATIONS

not
the inverter !!!

operators

or
one is enough !!!

and
mandatory !!!

LOGICAL TABLE (THE TRUTH TABLE)

2-BRANCH SELECTIONS (³IF´ STRUCTURES)

IF CONDITION THEN ACTIONS_IF_TRUE END IF Y

CONDITION ?

N IF CONDITION THEN ACTIONS_IF_TRUE ELSE ACTIONS_IF_FALSE END IF

MANY-BRANCH SELECTIONS (³CASE´ STRUCTURES)

CASE SELECTOR OF VALUE_1: ACTIONS_1 VALUE_2: ACTIONS_2 ... VALUE_N: ACTIONS_N END CASE 1 CASE SELECTOR OF VALUE_1: ACTIONS_1 VALUE_2: ACTIONS_2 ... VALUE_N: ACTIONS_N ELSE ACTIONS_ELSE END CASE 2

CASE SELECTOR OF N

ELSE

3

EXAMPLE #1 ± INPUT CONSTRAINTS

inputing the score between 0 and 100
BEGIN OUTPUT('PLEASE GIVE ME A SCORE 0-100 > ') INPUT(SCORE) IF SCORE  0 THEN IF SCORE  100 THEN OUTPUT('INPUT CORRECT!', CR) ELSE OUTPUT('INPUT OUT OF RANGE!', CR) END IF ELSE OUTPUT('INPUT OUT OF RANGE!', CR) END IF END.

BEGIN OUTPUT('PLEASE GIVE ME A SCORE 0-100 > ') INPUT(SCORE) IF (SCORE  0) AND (SCORE  100) THEN OUTPUT('INPUT CORRECT!', CR) ELSE OUTPUT('INPUT OUT OF RANGE!', CR) END IF END.

EXAMPLE #2 ± GRADE YOURSELF!!!

grading to the STIKI¶s policy
BEGIN OUTPUT('PLEASE GIVE ME A SCORE 0-100 > ') INPUT(SCORE) IF (SCORE  0) AND (SCORE  100) THEN OUTPUT('YOU HAVE GOT ') IF SCORE  80 THEN OUTPUT('A', CR) ELSE IF SCORE  75 THEN OUTPUT('B+', CR) ELSE IF SCORE  70 THEN OUTPUT('B', CR) ELSE IF SCORE  61 THEN OUTPUT('C+', CR) ELSE IF SCORE  56 THEN OUTPUT('C', CR) ELSE IF SCORE  75 THEN OUTPUT('D', CR) ELSE OUTPUT('E', CR) END IF END IF END IF END IF END IF END IF ELSE OUTPUT('INPUT OUT OF RANGE!', CR) END IF END.

EXAMPLE #3 ± GRADE YOURSELF!!! (CASE VERSION)

grading to the STIKI¶s policy
BEGIN OUTPUT('PLEASE GIVE ME A SCORE 0-100 > ') INPUT(SCORE) IF (SCORE  0) AND (SCORE  100) THEN OUTPUT('YOU HAVE GOT ') CASE TRUNC(SCORE) OF 80..100: OUTPUT('A', CR) 75..79: OUTPUT('B+', CR) 70..74: OUTPUT('B', CR) 61..69: OUTPUT('C+', CR) 56..60: OUTPUT('C', CR) 40..55: OUTPUT('D', CR) ELSE OUTPUT('E', CR) END CASE ELSE OUTPUT('INPUT OUT OF RANGE!', CR) END IF END.

EXAMPLE #4 ± GRADE YOURSELF!!! (PURE CASE VERSION)

grading to the STIKI¶s policy
BEGIN OUTPUT('PLEASE GIVE ME A SCORE 0-100 > ') INPUT(SCORE) OUTPUT('YOU HAVE GOT ') CASE TRUNC(SCORE) OF 80..100: OUTPUT('A', CR) 75..79: OUTPUT('B+', CR) 70..74: OUTPUT('B', CR) 61..69: OUTPUT('C+', CR) 56..60: OUTPUT('C', CR) 40..55: OUTPUT('D', CR) 0..39: OUTPUT('E', CR) ELSE OUTPUT('YOUR INPUT OUT OF RANGE!', CR) END CASE END.

ROUTINE TASKS Find out the area of a circle, filter the inputs as neccessary. Find out the area of a triangle, filter the inputs as neccessary. Find out the area of a rectangle, filter the inputs as neccessary. Find out the area of a circle, a triangle, or a rectangle, accessed via a menu, and filter the inputs as neccessary.  Find out the y-value from given x-value of    

f ( x) ! 3x 3  5 x 2  2 x  6
 Find out the y-value from given x-value and a, b, c, and d of

f ( x ) ! ax 3  bx 2  cx  d

WHAT¶S NEXT?

repetitive statements (while, repeat, for), flow control, iteration, ...

scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->