Arrays and file handling
도입됨
13:08
프로그래밍
Here is a short program. It reads five test marks and prints the total. The five marks are eight, nine, seven, six and ten, so the total should be forty. Watch…
영어 내레이션 · 영어와 중국어 자막 전환 가능
이 수업의 내용
| English | 의미 |
|---|---|
| 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 |
배열(Data)와 파일(File)
- **배열(array)**는 하나의 변수에 같은 유형의 여러 값을 저장합니다.
- **파일(file)**은 프로그램 종료 후에도 데이터를 유지할 수 있게 합니다.
- 루프는 이 둘을 순차적으로 처리하는 자연스러운 방법입니다.
일차원 배열(One-dimensional arrays)
- 1D 배열은 단일 목록과 같으며, 각 값은 **인덱스(index)(위치 번호)**를 통해 찾을 수 있습니다.
DECLARE Scores : ARRAY[1:5] OF INTEGER
Scores[1] ← 90
FOR I ← 1 TO 5
INPUT Scores[I]
NEXT I
- 루프를 사용하여 전체 배열을 채우거나 읽습니다.

*1차원 배열은 한 변수에 여러 값을 저장하며, 각 값은 인덱스로 찾습니다.

An array is:
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
An array stores many same-type values under one name; each is accessed by its index.
이차원 배열(Two-dimensional arrays)
- 2D 배열은 **행(row)과 열(column)**이 있는 표와 같으며, 두 개의 인덱스
[row, column]를 사용합니다.
DECLARE Grid : ARRAY[1:3, 1:3] OF INTEGER
Grid[2, 3] ← 8 // row 2, column 3
- 2D 배열은 **루프 안의 루프(nested iteration)**를 사용하여 읽습니다.

*2차원 배열은 표와 같으며, 각 값은 두 개의 인덱스((행, 열))로 찾습니다.

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?
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
The first index is the row, the second the column — row 2, column 3.
Match each idea to what it means.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Arrays hold many values by index; a 2-D array is a grid; nested loops walk it; files are opened, used and closed.
파일 처리(File handling)
- 프로그램은 **파일(file)**에 데이터를 저장하여 프로그램 종료 후에도 보존될 수 있습니다.
- Open the file, use it, then close it:
OPENFILE "data.txt" FOR WRITE
WRITEFILE "data.txt", "Hello"
CLOSEFILE "data.txt"
- 완료 시 항상 파일을 **닫아(close)야 하며(
FOR READ**를 사용하여 다시 읽음).

카운터는 1씩 증가하며, 총계(total)는 누적 합계를 만듭니다
Put the steps of using a file in the correct order.
난이도 3/5 · 200코인 + 오늘 첫 완료 시 작은 보너스 추가
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.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
Closing saves any buffered data and frees the file for other programs.
이해했습니다
- 1D 배열은 하나의 인덱스로 접근하는 목록이며, 루프로 채우거나 읽습니다
- 2D 배열은
[row, column]로 접근하는 표이며, **중첩 루프(nested loops)**를 사용합니다 - 파일 처리: OPENFILE (READ/WRITE) → READFILE/WRITEFILE → CLOSEFILE
- 완료 시 항상 파일을 **닫아(close)**야 합니다
Scores 보유함 90 75 60 88 50 with the first index 1. What is Scores[4]?
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
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.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
Arrays live in RAM while the program runs; a file is saved to storage.
이 카드는 새로 추가되어 번역이 준비될 때까지 영어로 표시됩니다.
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
어떤 문제가 있었나요? 사이트 팀만 이 내용을 볼 수 있습니다.