Pemodelan untuk Komputasi : Selection II, Nested-IF, Multi-IF, dan Contoh Soal ( Bahasa Inggris )
Baca Materi Prasyarat Pemodelan untuk Komputasi : Logical Operator & Selection dan Contoh Soal ( Bahasa Inggris )
Introduction of Selection II
The Richter scale is a measurement of the strength of an earthquake. Every step in the scale, for example from 6.0 to 7.0, signifies a tenfold increase in the strength of the quake. We can categorize the scale into 5 categories: Category A (most structures fall), B (many buildings destroyed), C (many buildings considerably damaged, some collapse), D (damage to poorly constructed buildings), and E (no destruction of buildings). Write the program to categorize the Ritcher scale!
Notes :
- Is it enough to use only if-else structure to solve the previous problem?
- We need more than one alternative to categorize the Ritcher scale.
- Solution: use multiway if-else or nested if
Algorithms of Multiway IF – ELSE
We can use multi-way IF – ELSE if there are several alternatives that are needed to be chosen by our algorithm.
IF (conditions) then steps
ELSE-IF (conditions) then steps
…
…
...
ELSE stepsFlowchart: Multiway IF – ELSE
Flowchart of Multiway IF – ELSE
Multiway IF – ELSE Example
Algoritmic Table
Flowchart
Nested IF
Nested IF is an if statement inside another. Any problem that involves a multiway IF – ELSE can be solved using Nested IF. Furthermore, there are no differences between multiway IF – ELSE and Nested IF
Nested IF Example
Examples
Tax Regulation
Write an algorithm and draw the flowchart to calculate the income tax based on this regulation!
Algorithm: Tax Regulation
Exercise 1
Salary
You are given the salaries of these 3 employees working in the accounts department. You have to find out the minimum salary of those employees. Write the algorithms and draw the flowchart!
The Colors
In RYB colors, there are three primary colors: red, blue, and yellow. We can make a secondary color by mixing up two primary colors. We can create green by mixing up the blue and the yellow. The orange is created by mixing up red and yellow. The purple is created by mixing up red and blue.
Given two primary colors, make an algorithm to find out what is the secondary color created by those primary colors !
Leap Year
Write an algorithm and draw the flowchart to determine if a year is a leap year. A leap year is a calendar day containing one additional day. These extra days occur in years which are multiples of four (with the exception of years divisible by 100 but not by 400).
Zapping
My TV remote is almost broken. Only △ and ▽ are working. My TV has 100 channels conveniently numbered 0 through 99. They are cyclic, in the sense that if I’m on channel 99 and press △ I’ll go to channel 0. Similarly, if I’m on channel 0 and press ▽ I’ll change to channel 99. I would like a program that, given the channel I’m currently watching and the channel I would like to change to, tells me the minimum number of button presses I need to reach that channel.
Write the algorithm and draw the flowchart!
How Old Are You
Given two dates: current date and a birth date of a person. Write your algorithm and draw the flowchart to calculate how old a person is! Assume that there are no invalid date (current date is < birth date).
Example:
- Current Date: 12/11/2007
- Birth Date: 01/01/1984
- Age: 23
Chocolate Bar
We want to make a package of goal kilos of chocolate. We have small bars (1 kilo each) and big bars (5 kilos each). Count the number of small bars to use, assuming we always use big bars before small bars. Output -1 if it can't be done.
Example :
Min latihan soalnya bisa ditambah dengan penyelesaiannya gak, soalnya bingung ngerjainnya
BalasHapusPosting Komentar