Sains Komputer Form 5 Trial Tips
Your interactive revision portal for the upcoming Sains Komputer trials. We've compiled textbook diagrams directly from chapters covering algorithms, standard libraries, client-side scripting (JavaScript), procedures/functions, and memory visualization.
Finding the Maximum Value
Proses Mencari Nilai Maksimum (Rajah 3.1.28)
This diagram outlines the logical sequence for finding the maximum value within a collection of items (such as an array):
- Beri nilai awal maksimum (Initialize Max Value): Assign the first element of the array or a very small default number as the initial maximum.
- Banding nilai dalam senarai (Compare with current items): Loop through the remaining elements and compare each item against the current maximum value.
- Dapat nilai maksimum terkini (Update new maximum): If a compared element is larger than the stored maximum, update the stored value with the new maximum. Repeat until all elements have been evaluated.
Introduction to Standard Libraries
Kelebihan & Pengenalan Standard Library (Bahagian 3.1.5)
A Standard Library (Perpustakaan Standard) is a collection of built-in methods and functions supplied by the programming language specification to assist programmers in coding common operations.
- Efficiency: Saves development time by providing pre-built functions for data structures, algorithms, math operations, and input/output mechanisms.
- Common JavaScript Standard Libraries in the Textbook:
math.js: Used for mathematical formulas likemath.sqrt()(square root) andmath.pow()(exponents).date.js: Used for date tracking functions such asdate.now()and formatting.
Fungsi math.js (Mathematical Library Methods)
Jadual 3.1.30 Fungsi-fungsi dalam math.js
The textbook specifies five core operations within the math.js standard library that you should memorize for paper questions:
| Fungsi (Method Call) | Penerangan (English Translation) |
|---|---|
math.add(x, y) |
Menambah dua nombor (Adds two numbers) |
math.divide(x, y) |
Membahagi dua nombor (Divides x by y) |
math.subtract(x, y) |
Menolak dua nombor (Subtracts y from x) |
math.pow(x, y) |
Mengira kuasa kepada nombor (Raises x to the power of y) |
math.sqrt(x) |
Mengira punca kuasa bagi nombor (Calculates square root of x) |
Modular Programming & Sub-routines
Rajah 3.1.44 Modul Utama dan Subatur Cara
Modular programming divides a single script into smaller, isolated components. In client-side scripting, this is achieved using subatur cara (sub-routines).
- Modul Utama (Main Module): Represents the main script flow which invokes helper modular blocks.
- Sub-routine Categories:
- Prosedur (Procedure): A block of code designed to perform a task but does not return a value back to the caller.
- Fungsi (Function): Performs operations and returns a value back to the caller using a return statement.
Procedures vs Functions
Perbezaan antara Prosedur dengan Fungsi (Jadual 3.1.35)
Understanding when to use a Procedure vs a Function is a guaranteed scoring topic. Here is the formal breakdown:
| Aspek | Prosedur (Procedure) | Fungsi (Function) |
|---|---|---|
| Memulangkan Nilai | Tidak memulangkan nilai | Memulangkan nilai |
| Contoh Panggilan | toCelcius(fahrenheit); |
celcius = toCelcius(fahrenheit); |
Array Declaration & Manual Retrieval
Mengisytiharkan Array & Akses Satu per Satu (ms206(a))
For ms206(a), the textbook demonstrates retrieving elements one by one manually using indices to sum up numbers. You must know how arrays are declared and written in both JavaScript and Java, and understand their core differences.
// Declaring and initializing array in JavaScript
var no = [5, -1, 4, 12, 8];
var jumlah = 0;
// Adding values manually element-by-element
jumlah = no[0] + no[1] + no[2] + no[3] + no[4];
document.write(jumlah); // Outputs: 28
// Declaring and initializing array in Java (Fixed data types)
int[] no = {5, -1, 4, 12, 8};
int jumlah = 0;
// Adding values manually element-by-element
jumlah = no[0] + no[1] + no[2] + no[3] + no[4];
System.out.println(jumlah); // Outputs: 28
| Feature | JavaScript Array | Java Array |
|---|---|---|
| Type System | Dynamic typing (can hold multiple types: strings, numbers, etc.) | Static typing (must declare type e.g., int[], homogeneous elements) |
| Declaration Syntax | var no = [5, -1, 4, 12, 8]; |
int[] no = {5, -1, 4, 12, 8}; |
| Size Constraint | Dynamic size (can grow/shrink) | Fixed size (once declared, the size cannot be changed) |
Loops and Memory Blocks
Menggunakan Ulangan untuk Menjumlahkan Senarai (ms206(b))
For ms206(b), you must know how to change loops from for to while, while to for, or do-while. Additionally, you are required to know how to draw a Blok Memori (Block Memory) diagram for arrays.
Loop Conversion Playground
Select a language and loop type to view side-by-side structures:
var no = [5, -1, 4, 12, 8];
var jumlah = 0;
var i;
for (i = 0; i < 5; i++) {
jumlah = jumlah + no[i];
}
document.write(jumlah);
var no = [5, -1, 4, 12, 8];
var jumlah = 0;
var i = 0; // Initialize control variable
while (i < 5) { // Loop condition
jumlah = jumlah + no[i];
i++; // Increment variable
}
document.write(jumlah);
var no = [5, -1, 4, 12, 8];
var jumlah = 0;
var i = 0; // Initialize control variable
do {
jumlah = jumlah + no[i];
i++; // Increment variable
} while (i < 5); // Loop condition (executes at least once)
document.write(jumlah);
int[] no = {5, -1, 4, 12, 8};
int jumlah = 0;
for (int i = 0; i < 5; i++) {
jumlah = jumlah + no[i];
}
System.out.println(jumlah);
int[] no = {5, -1, 4, 12, 8};
int jumlah = 0;
int i = 0; // Initialize control variable
while (i < 5) { // Loop condition
jumlah = jumlah + no[i];
i++; // Increment variable
}
System.out.println(jumlah);
int[] no = {5, -1, 4, 12, 8};
int jumlah = 0;
int i = 0; // Initialize control variable
do {
jumlah = jumlah + no[i];
i++; // Increment variable
} while (i < 5); // Loop condition
System.out.println(jumlah);
Interactive Block Memory Visualizer (Blok Memori)
In SPM exams, you must draw array memory as contiguous boxes. Hover/click cell nodes to view index accesses:
Feedback & Queries
Submit form questions or overall website feedback