Arrays and file handling
הוצג
13:08
תכנות מחשב
הנה תוכנית קצרה. היא קוראת חמש ציוני מבחן והדפיסה את הסכום הכולל. החמש ציונים הם שמונה, תשע, שבע, שש ועשר, ולכן הסכום הכולל אמור להיות ארבעים. הצפו…
קריינות באנגלית · כתוביות באנגלית ובסינית 中文 שאפשר להחליף ביניהן
בשיעור הזה
| 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 |
מערכים וקבצים
- מערך מאחסן הרבה ערכים מאותו סוג במשתנה אחד.
- קובץ מאפשר לתוכנית לשמור נתונים לאחר שפסקה הפעילה.
- לולאות הן הדרך הטבעית לעבור על שניהם.
מערכים חד-ממדיים
- מערך 1D דומה לרשימה אחת; כל ערך נמצא באמצעות אינדקס (מספר מיקום).
DECLARE Scores : ARRAY[1:5] OF INTEGER
Scores[1] ← 90
FOR I ← 1 TO 5
INPUT Scores[I]
NEXT I
- לולאה ממלאה או קוראת את כל המערכת.

מערך 1D מכיל הרבה ערכים במשתנה אחד; כל אחד מהם נמצא לפי האינדקס שלו.

An array is:
רמת קושי 1/5 · 100 מטבעות + בונוס קטן בהשלמה הראשונה היום
An array stores many same-type values under one name; each is accessed by its index.
מערכים דו-ממדיים
- מערך 2D הוא כמו טבלה עם שורות ועמודות, המשתמשת ב-שני אינדקסים
[row, column].
DECLARE Grid : ARRAY[1:3, 1:3] OF INTEGER
Grid[2, 3] ← 8 // row 2, column 3
- לקרוא מערך 2D יש להשתמש בלולאה בתוך לולאה (איטרציה מקוננת).

מערך 2D הוא טבלה; כל ערך נמצא באמצעות שני אינדקסים, (שורה, עמודה).

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.
טיפול בקבצים
- תוכנית יכולה לאחסן נתונים בקובץ כדי שהם יישארו קיימים לאחר עצירת התוכנית.
- פתח את הקובץ, השתמש בו, ולאחר מכן סגור אותו:
OPENFILE "data.txt" FOR WRITE
WRITEFILE "data.txt", "Hello"
CLOSEFILE "data.txt"
- תמיד סגור קובץ כשסיימת (השתמש ב
FOR READלקריאה חוזרת).

מדד סופר פונה כלפי מעלה ב-1; סכום מצטבר בונה סכום רצף
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]; יש להשתמש בלולאות מקוננות - טיפול בקבצים: OPENFILE (READ/WRITE) → READFILE/WRITEFILE → CLOSEFILE
- תמיד סגור קובץ כשסיימת
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
מה השתבש? רק צוות האתר רואה זאת.