Logika Dan Algoritma, Pertemuan 2
Click here to load reader
-
Upload
vi-love-dy -
Category
Documents
-
view
104 -
download
17
description
Transcript of Logika Dan Algoritma, Pertemuan 2
![Page 1: Logika Dan Algoritma, Pertemuan 2](https://reader038.fdocuments.in/reader038/viewer/2022102417/55cf9d31550346d033ac9d0f/html5/thumbnails/1.jpg)
LOGICS AND ALGORITHMSLOGICS AND ALGORITHMS
by: Hendra Suprayogi, S.Kom., ST.
The 2nd Subject
Logical Operations ●2-branch Conditional Structures ●
Many-branch Conditional Structures ●
![Page 2: Logika Dan Algoritma, Pertemuan 2](https://reader038.fdocuments.in/reader038/viewer/2022102417/55cf9d31550346d033ac9d0f/html5/thumbnails/2.jpg)
BOOLEAN TYPES
0FALSE
NO
0FALSE
NO
1TRUEYES
1TRUEYES
![Page 3: Logika Dan Algoritma, Pertemuan 2](https://reader038.fdocuments.in/reader038/viewer/2022102417/55cf9d31550346d033ac9d0f/html5/thumbnails/3.jpg)
LOGICAL OPERATIONS
notthe inverter !!!
operators
orone is enough !!!
andmandatory !!!
![Page 4: Logika Dan Algoritma, Pertemuan 2](https://reader038.fdocuments.in/reader038/viewer/2022102417/55cf9d31550346d033ac9d0f/html5/thumbnails/4.jpg)
LOGICAL TABLE (THE TRUTH TABLE)
A B not A not B
FALSE
FALSE
TRUE
TRUE
FALSE
TRUE
FALSE
TRUE
TRUE
TRUE
FALSE
FALSE
TRUE
FALSE
TRUE
FALSE
A or B
FALSE
TRUE
TRUE
TRUE
A and B
FALSE
FALSE
FALSE
TRUE
A B not A not B
FALSE
FALSE
TRUE
TRUE
FALSE
TRUE
FALSE
TRUE
TRUE
TRUE
FALSE
FALSE
TRUE
FALSE
TRUE
FALSE
A or B
FALSE
TRUE
TRUE
TRUE
A and B
FALSE
FALSE
FALSE
TRUE
![Page 5: Logika Dan Algoritma, Pertemuan 2](https://reader038.fdocuments.in/reader038/viewer/2022102417/55cf9d31550346d033ac9d0f/html5/thumbnails/5.jpg)
2-BRANCH SELECTIONS (“IF” STRUCTURES)
CONDITION ?Y
N
IF CONDITION THEN ACTIONS_IF_TRUEEND IF
IF CONDITION THEN ACTIONS_IF_TRUEELSE ACTIONS_IF_FALSEEND IF
![Page 6: Logika Dan Algoritma, Pertemuan 2](https://reader038.fdocuments.in/reader038/viewer/2022102417/55cf9d31550346d033ac9d0f/html5/thumbnails/6.jpg)
MANY-BRANCH SELECTIONS (“CASE” STRUCTURES)
CASESELECTOR
OF1
3
CASE SELECTOR OF VALUE_1: ACTIONS_1 VALUE_2: ACTIONS_2 ... VALUE_N: ACTIONS_NEND CASE
2N
ELSECASE SELECTOR OF VALUE_1: ACTIONS_1 VALUE_2: ACTIONS_2 ... VALUE_N: ACTIONS_NELSE ACTIONS_ELSEEND CASE
![Page 7: Logika Dan Algoritma, Pertemuan 2](https://reader038.fdocuments.in/reader038/viewer/2022102417/55cf9d31550346d033ac9d0f/html5/thumbnails/7.jpg)
EXAMPLE #1 – INPUT CONSTRAINTS
inputing the score between 0 and 100 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 IFEND.
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 IFEND.
![Page 8: Logika Dan Algoritma, Pertemuan 2](https://reader038.fdocuments.in/reader038/viewer/2022102417/55cf9d31550346d033ac9d0f/html5/thumbnails/8.jpg)
EXAMPLE #2 – GRADE YOURSELF!!!
grading to the STIKI’s policy 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 IFEND.
![Page 9: Logika Dan Algoritma, Pertemuan 2](https://reader038.fdocuments.in/reader038/viewer/2022102417/55cf9d31550346d033ac9d0f/html5/thumbnails/9.jpg)
EXAMPLE #3 – GRADE YOURSELF!!! (CASE VERSION)
grading to the STIKI’s policy 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 IFEND.
![Page 10: Logika Dan Algoritma, Pertemuan 2](https://reader038.fdocuments.in/reader038/viewer/2022102417/55cf9d31550346d033ac9d0f/html5/thumbnails/10.jpg)
EXAMPLE #4 – GRADE YOURSELF!!! (PURE CASE VERSION)
grading to the STIKI’s policy 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 CASEEND.
![Page 11: Logika Dan Algoritma, Pertemuan 2](https://reader038.fdocuments.in/reader038/viewer/2022102417/55cf9d31550346d033ac9d0f/html5/thumbnails/11.jpg)
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
• 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
6253)( 23 xxxxf
• Find out the y-value from given x-value and a, b, c, and d of • Find out the y-value from given x-value and a, b, c, and d of
dcxbxaxxf 23)(
![Page 12: Logika Dan Algoritma, Pertemuan 2](https://reader038.fdocuments.in/reader038/viewer/2022102417/55cf9d31550346d033ac9d0f/html5/thumbnails/12.jpg)
WHAT’S NEXT?
repetitive statements (while, repeat, for), flow control, iteration, ...