Pemodelan untuk Komputasi : Modularization dan Contoh Soal ( Bahasa Inggris )
Introduction
Example: to calculate the volume of a cone, there are 2 subprocesses:
- Calculate the base area
- Multiply: the base area with the height of cone and 1/3
Example: The Volume of A Cone
Module
A module is a named subprocess. Modules are vital when writing large programs that consist of many individual parts. Syntactic pattern for naming a subprocess as a module:
Parameters are the input of the subprocess/algorithm.
Example: The Volume of A Cone
Invoking A Module
To invoke a module, mention the name along with the parameters. So, the statement baseArea(10) will calculate the area of circle with radius = 10. The result is 314. Example :
Example: Vowel
To count how many vowel in a word, there are 2 subprocesses:
- A: Check if a letter is vowel
- B: Do subprocess A for all the letters in the word
The statement ltr('a') will check if a is a vowel. The statement ltr('v') will check if v is a vowel
Example: Fraction 1
Write a module to compute the addition of two fractions.
Example: Fraction 2
Write a module to compute the addition of two fractions.
EmoticonEmoticon