Arrays and file handling
Diperkenalkan
13:08
Pemrograman
Berikut program pendek. Program ini membaca lima nilai ujian tes dan mencetak totalnya. Lima nilai tersebut adalah delapan, sembilan, tujuh, enam, dan sepuluh, sehingga total seharusnya empat puluh. Perhatikan…
Narasi bahasa Inggris · takarir bahasa Inggris dan 中文 yang dapat dipilih
Dalam pelajaran ini
| English | Makna |
|---|---|
| array/əˈreɪ/ | |
| file/faɪl/ | A named collection of data stored and managed as a unit. |
| variable/ˈveərɪəbl/ | A quantity or named value that can change or take different values. |
| data/ˈdeɪtə/ | Recorded facts, observations or values used for analysis or processing. |
| Loops | The natural way to work through both. |
| One-dimensional arrays | |
| 1D array | |
| index/ˈɪndeks/ | |
| READ | |
| Two-dimensional arrays | |
| 2D array/ˌtuː ˈdiː əˈreɪ/ | |
| nested/ˈnestɪd/ | |
| iteration/ˌɪtəˈreɪʃn/ | Repeating a sequence of instructions or calculations. |
| file handling/faɪl ˈhændlɪŋ/ | |
| pseudocode/ˈsuːdəʊkəʊd/ | A language-independent description of an algorithm using structured, programming-like statements. |
| loop variable/luːp ˈveərɪəbl/ | |
| OPENFILE | |
| READFILE | |
| WRITEFILE | |
| CLOSEFILE |
Array dan file
- Array menyimpan banyak nilai dari tipe yang sama dalam satu variabel.
- File memungkinkan program menyimpan data setelah berhenti.
- Loop adalah cara alami untuk memproses keduanya.
Array satu dimensi
- Array 1D seperti daftar tunggal; setiap nilai ditemukan oleh indeks (nomor posisi).
DECLARE Scores : ARRAY[1:5] OF INTEGER
Scores[1] ← 90
FOR I ← 1 TO 5
INPUT Scores[I]
NEXT I
- Loop mengisi atau membaca seluruh array.

Array 1D menyimpan banyak nilai dalam satu variabel; masing-masing ditemukan oleh indeksnya.

An array is:
Kesulitan 1/5 · 100 koin + bonus kecil pada penyelesaian pertama hari ini
An array stores many same-type values under one name; each is accessed by its index.
Array dua dimensi
- Array 2D seperti tabel dengan baris dan kolom, menggunakan dua indeks
[row, column].
DECLARE Grid : ARRAY[1:3, 1:3] OF INTEGER
Grid[2, 3] ← 8 // row 2, column 3
- Anda membaca array 2D dengan loop di dalam loop (iterasi bersarang).

Array 2D adalah tabel; setiap nilai ditemukan oleh dua indeks, (baris, kolom).

Index a 2-D array: Grid[Row, Col]
A 2-D array is a grid of values. Grid[Row, Col] reaches exactly one cell — the row first, then the column. Cambridge counts both from 1.
In grid[2, 3], which cell is accessed?
Kesulitan 1/5 · 100 koin + bonus kecil pada penyelesaian pertama hari ini
The first index is the row, the second the column — row 2, column 3.
Match each idea to what it means.
Kesulitan 2/5 · 140 koin + bonus kecil pada penyelesaian pertama hari ini
Arrays hold many values by index; a 2-D array is a grid; nested loops walk it; files are opened, used and closed.
Penanganan file
- Program dapat menyimpan data dalam file agar tetap ada setelah program berhenti.
- Buka file, gunakan, lalu tutup file:
OPENFILE "data.txt" FOR WRITE
WRITEFILE "data.txt", "Hello"
CLOSEFILE "data.txt"
- Selalu tutup file saat selesai (gunakan
FOR READuntuk membacanya kembali).

Counter menghitung naik 1; total membangun jumlah berjalan
Put the steps of using a file in the correct order.
Kesulitan 3/5 · 200 koin + bonus kecil pada penyelesaian pertama hari ini
Always open first, then do the reading/writing, then close to save buffered data and free the file.
You should always close a file when you have finished using it.
Kesulitan 1/5 · 100 koin + bonus kecil pada penyelesaian pertama hari ini
Closing saves any buffered data and frees the file for other programs.
Anda telah memahaminya
- array 1D adalah daftar yang diakses oleh satu indeks; isi/baca dengan loop
- array 2D adalah tabel yang diakses oleh
[row, column]; gunakan loop bersarang - penanganan file: OPENFILE (READ/WRITE) → READFILE/WRITEFILE → CLOSEFILE
- selalu tutup file saat selesai
Scores memegang 90 75 60 88 50 with the first index 1. What is Scores[4]?
Kesulitan 2/5 · 140 koin + bonus kecil pada penyelesaian pertama hari ini
Counting from index 1: 90, 75, 60, 88.
Data in an array is lost when the program stops, but data written to a file is kept.
Kesulitan 1/5 · 100 koin + bonus kecil pada penyelesaian pertama hari ini
Arrays live in RAM while the program runs; a file is saved to storage.
Kartu ini baru, jadi ditampilkan dalam bahasa Inggris sampai terjemahannya siap.
You've got it
- a 1D array is a list reached by one index; fill/read it with a loop
- a 2D array is a table reached by
[row, column]; use nested loops - file handling: OPENFILE 打开文件 (READ/WRITE) → READFILE 读取文件/WRITEFILE 写入文件 → CLOSEFILE 关闭文件
- always close a file when done
Apa yang salah? Hanya tim situs yang dapat melihatnya.