Skip to content · ⁨الانتقال إلى المحتوى⁩

Programming · ⁨البرمجة⁩

IGCSE Computer Science · ⁨IGCSE علوم الحاسوب⁩ · Topic 8 · ⁨الموضوع 8⁩

Video lesson for this topic · ⁨درس فيديو لهذا الموضوع⁩ Open the video page · ⁨افتح صفحة الفيديو⁩
13:16

البرمجة

هنا برنامج قصير. يقرأ خمس علامات اختبار ويطبع المجموع. العلامات الخمس هي ثمانية، تسعة، سبعة، ستة وعشرة، لذا يجب أن يكون المجموع أربعين. شاهد…

English narration · English + 中文 subtitles burned in · ⁨سرد باللغة الإنجليزية · ترجمة مدمجة بالإنجليزية + الصينية⁩

8.1

Variables and constants · ⁨المتغيرات والثوابت⁩

Syllabus · ⁨المنهج⁩
English
Candidates should be able to: Notes and guidance
1 Declare and use variables and constants
2 Understand and use basic data types • Including: – integer – real – char – string – Boolean
3 Understand and use input and output
4 (a) Understand and use the concept of sequence
(b) Understand and use the concept of selection • Including: – IF statements – CASE statements
(c) Understand and use the concept of iteration • Including: – count-controlled loops – pre-condition loops – post-condition loops
(d) Understand and use the concepts of totalling and counting
(e) Understand and use the concept of string handling • Including: – length – substring – upper – lower • The first character of the string can be position zero or one
(f) Understand and use arithmetic, relational and logical operators • Arithmetic, limited to: – + – – – / – * – ^ (raised to power of) – MOD – DIV • Relational, limited to: – = – < – <= – > – >= – <> (not equal to) • Logical, limited to: – AND – OR – NOT
5 Understand and use nested statements • Including nested selection and iteration • Candidates will not be required to write more than three levels of nested statements
6 (a) Understand what is meant by procedures, functions and parameters (b) Define and use procedures and functions, with or without parameters (c) Understand and use local and global variables • Procedures and functions may have up to three parameters
7 Understand and use library routines • Including: – MOD – DIV – ROUND – RANDOM
8 Understand how to create a maintainable program • Including appropriate use of: – meaningful identifiers – the commenting feature provided by the programming language – procedures and functions – relevant and appropriate commenting of syntax • Use meaningful identifiers for: – variables – constants – arrays – procedures and functions
العربية
يجب أن يكون المرشحون قادرين على: ملاحظات وإرشادات
1 أعْلن واستخدم المتغيرات والثوابت
2 افهم واستخدم أنواع البيانات الأساسية • يشمل: – عدد صحيح – عدد حقيقي – حرف – سلسلة نصية – منطقية
3 افهم واستخدم الإدخال والإخراج
4 (أ) افهم واستخدم مفهوم التسلسل
(ب) افهم واستخدم مفهوم الاختيار • يشمل: – جملات IF – جملات CASE
(ج) افهم واستخدم مفهوم التكرار • يشمل: – حلقات التحكم بالعداد – حلقات الشرط المسبق – حلقات الشرط اللاحق
(د) افهم واستخدم مفاهيم المجموع والعد
(هـ) افهم واستخدم مفهوم معالجة السلاسل النصية • يشمل: – الطول – الجزء الجزئي – أحرف كبيرة – أحرف صغيرة • يمكن أن يكون أول حرف في السلسلة عند الموقع صفر أو واحد
(و) افهم واستخدم العمليات الحسابية والعلاقية والمنطقية • الحسابية، مقيدة بـ: – + – – – / – * – ^ (مرفوعة لأس) – MOD – DIV • العلاقية، مقيدة بـ: – = – < – <= – > – >= – <> (غير مساوية) • المنطقية، مقيدة بـ: – AND – OR – NOT
5 افهم واستخدم الجمل المتداخلة • يشمل الجمل المختارة والمتداخلة والحلقات المتداخلة • لن يُطلب من المترشحين كتابة أكثر من ثلاث مستويات من الجمل المتداخلة
6 (أ) افهم ما يُقصَد بـالجراءات والدوال والمعلمات (ب) عرّف واستخدم الإجراءات والدوال، مع أو بدون معلمات (ج) افهم واستخدم المتغيرات المحلية والعالمية • قد تحتوي الإجراءات والدوال على ما يصل إلى ثلاثة معلمات
7 افهم واستخدم الروتين المكتبي • يشمل: – MOD – DIV – ROUND – RANDOM
8 افهم كيفية إنشاء برنامج قابل للصيانة • بما في ذلك الاستخدام المناسب لـ: – المعرّفات ذات المعنى – ميزة التعليق التي يوفرها لغة البرمجة – الإجراءات والدوال – التعليق المناسب والمعني على بناء الجملة • استخدم معرّفات ذات معنى لـ: – المتغيرات – الثوابت – المصفوفات – الإجراءات والدوال

Source: Cambridge International syllabus · ⁨المصدر: منهج كامبريدج الدولي⁩

English

A variable 变量 is a named store that holds a value which can change while the program runs. A constant 常量 is a named store whose value is fixed and does not change.

You should declare 声明 them (say their name and type) before use:

Use a constant for a value that never changes (like Pi), so it is set in one place and is easy to read.

العربية

المتغير هو مستودع مُسمى يحمل قيمة يمكن تغييرها أثناء تشغيل البرنامج. الثابت هو مستودع مُسمى قيمته ثابتة ولا تتغير.

متغير اسمه age يحمل القيمة 16
المتغير هو مخزن مسمّى يمكن أن تتغير قيمته
أسطر من كود البرنامج على الشاشة
المتغيرات والثوابت هي مستودعات مُسمية للقيم، تُحدد في كود البرنامج

يجب عليك إعلان them (ذكر اسمها ونوعها) قبل الاستخدام:

DECLARE Score : INTEGER
DECLARE Name : STRING
CONSTANT Pi ← 3.142
وحدتا ذاكرة RAM
أثناء تشغيل البرنامج، تُحفظ متغيراته في ذاكرة الكمبيوتر (RAM)

استخدم ثابتاً لقيمة لا تتغير أبداً (مثل Pi)، بحيث تُحدد في مكان واحد وسهلة القراءة.

Explore · ⁨استكشف⁩

Variables and assignment

Step through the lines and watch each variable take its new value.

Vocabulary · ⁨مفردات⁩ Train · ⁨تدريب⁩
English العربية
variable/ˈveərɪəbl/ حدث
constant/ˈkɒnstənt/ ثابت
declare/dɪˈkleə/ إعلان
integer/ˈɪntɪdʒə/ integer
real/rɪəl/ حقيقي
char/tʃɑː/ حرف
string/strɪŋ/ سلسلة نصية
8.1

Data types · ⁨أنواع البيانات⁩

English

A data type 数据类型 says what kind of value a variable holds. You must know five basic types.

Type Holds Example
integer 整数 a whole number 42, -7
real 实数 a number with a decimal point 3.14, -0.5
char 字符 a single character 'A', '?'
string 字符串 a sequence of characters "Hello"
Boolean 布尔值 one of two values TRUE or FALSE
العربية

نوع البيانات يوضح نوع القيمة التي يحملها المتغير. يجب أن تعرف خمسة أنواع أساسية.

أنواع البيانات: عدد صحيح (7)، حقيقي (3.5)، حرف ('A')، سلسلة نصية ("hello")، منطقي (true/false)
أنواع البيانات الأساسية: عدد صحيح، عدد حقيقي، حرف، نص ومنطقي
النوع يحتوي على مثال
عدد صحيح عدد صحيح 42، -7
حقيقي عدداً بنقطة عشرية 3.14، -0.5
حرف حرف واحد 'A'، '?'
string تسلسل من الأحرف "Hello"
Boolean أحد قيمتين TRUE أو FALSE
Vocabulary · ⁨مفردات⁩ Train · ⁨تدريب⁩
English العربية
data type/ˈdeɪtə taɪp/ نوع البيانات
Boolean/ˈbuːlɪən/ Boolean
8.1

Input and output · ⁨الإدخال والإخراج⁩

English

Input 输入 reads a value from the user. Output 输出 shows a value on the screen.

العربية

الإدخال يقرأ قيمة من المستخدم. الإخراج يعرض قيمة على الشاشة.

OUTPUT "What is your name?"
INPUT Name
OUTPUT "Hello ", Name
Vocabulary · ⁨مفردات⁩ Train · ⁨تدريب⁩
English العربية
input/ˈɪnpʊt/ مدخلات
output/ˈaʊtpʊt/ نقرة فأرة تُبدأ عملاً هي مثال على
sequence/ˈsiːkwəns/ تسلسل
selection/sɪˈlekʃn/ اختيار
iteration/ˌɪtəˈreɪʃn/ التكرار
8.1

The three basic structures · ⁨الهياكل الأساسية الثلاثة⁩

English

Every program is built from three control structures.

Sequence

Sequence 顺序 means the steps run one after another, in order, from top to bottom.

Selection

Selection 选择 chooses which steps to run, based on a condition. Use an IF statement, or a CASE statement when there are many choices.

Iteration

Iteration 迭代 (a loop 循环) repeats steps. There are three kinds.

A count-controlled loop 计数循环 repeats a fixed number of times:

A pre-condition loop 前测循环 checks the condition before each repeat, so it may run zero times:

A post-condition loop 后测循环 checks the condition after each repeat, so it always runs at least once:

العربية

يتم بناء كل برنامج من ثلاثة هياكل تحكم.

ثلاثة مخططات تدفق صغيرة: التسلسل (صناديق في خط)، الاختيار (اختبار يتفرع بطريقتين)، والتكرار (اختبار مع جسم يعود للتكرار)
الهياكل الثلاثة للتحكم: التسلسل ينفذ الخطوات بالترتيب، الاختيار يختار فرعًا، التكرار يعيد تنفيذ الجسم

التسلسل

التسلسل يعني أن الخطوات تُنفذ واحدًا تلو الآخر، بالترتيب، من الأعلى إلى الأسفل.

INPUT Length
INPUT Width
Area ← Length * Width
OUTPUT Area

الاختيار

الاختيار يحدد أي الخطوات سيتم تنفيذها، بناءً على شرط ما. استخدم جملة IF، أو جملة CASE عندما تكون هناك خيارات عديدة.

IF Score >= 50
  THEN
    OUTPUT "Pass"
  ELSE
    OUTPUT "Fail"
ENDIF
CASE OF Grade
    'A' : OUTPUT "Excellent"
    'B' : OUTPUT "Good"
    OTHERWISE OUTPUT "Keep trying"
ENDCASE

التكرار

التكرار (الحلقة) يعيد تنفيذ الخطوات. هناك ثلاثة أنواع.

حلقة محدودة العداد تكرر عددًا ثابتًا من المرات:

FOR I ← 1 TO 5
    OUTPUT "Hello"
NEXT I

حلقة الشرط المسبق تتحقق من الشرط قبل كل تكرار، لذا قد لا تُنفذ أبدًا:

WHILE Answer <> "stop" DO
    INPUT Answer
ENDWHILE

حلقة الشرط اللاحق تتحقق من الشرط بعد كل تكرار، لذا تُنفذ دائمًا مرة واحدة على الأقل:

REPEAT
    INPUT Password
UNTIL Password = "secret"
مخطط تدفق حلقتين: WHILE يختبر الشرط قبل الجسم؛ REPEAT يشغل الجسم أولاً ثم يختبر بعد ذلك
حلقة الشرط المسبق (WHILE) تختبر قبل الجسم، لذا قد لا تُنفذ أبدًا؛ حلقة الشرط اللاحق (REPEAT) تختبر بعد، لذا تُنفذ مرة واحدة على الأقل
Explore · ⁨استكشف⁩

How an IF … ELSE IF ladder decides

The conditions are tested top to bottom; the FIRST one that is true runs and the rest are skipped. Slide the score and watch which branch lights up.

Explore · ⁨استكشف⁩

Selection

Change the value and watch which branch runs — selection in action.

Vocabulary · ⁨مفردات⁩ Train · ⁨تدريب⁩
English العربية
loop/luːp/ متغير
count-controlled loop/kaʊnt kənˈtrəʊld luːp/ حلقة محكومة بعدد العدادات
pre-condition loop/priː kənˈdɪʃn luːp/ حلقة الشرط المسبق
post-condition loop/pəʊst kənˈdɪʃn luːp/ حلقة الشرط اللاحق
length/leŋθ/ طول
8.1

Totalling and counting · ⁨الجمع العودي والعد⁩

English
  • totalling 求和 — keep adding values to a running total: Total ← Total + Value.
  • counting 计数 — add 1 to a counter each time: Count ← Count + 1.

Worked example. A program must read 5 marks, then output the total and the average.

Two lines carry the marks. Total ← 0 must sit before the loop: put it inside and the total resets on every pass, so the program outputs only the last mark. And Average ← Total / 5 must sit after the loop, because the total is not complete until every mark has been added. Initialise before, calculate after - that ordering is what the question is really testing.

العربية
  • الجمع العودي — استمر في إضافة القيم إلى مجموع متراكم: Total ← Total + Value.
  • العد — أضف 1 إلى عداد كل مرة: Count ← Count + 1.
count = count + 1 يعد تصاعدياً بمقدار 1؛ total = total + value يضيف إلى مجموع تراكمي
عداد يعد تصاعدياً بمقدار 1؛ المجموع يبني مجموعاً تراكمياً

جدول تتبع يتبع حلقة تمر على القيم 4، 7 و5: total يتغير عبر 0، 4، 11، 16 بينما count يتغير عبر 0، 1، 2، 3 *جدول التتبع يتتبع حلقة الجمع العودي والعد خطوة بخطوة

Total ← 0
FOR I ← 1 TO 10
    INPUT Mark
    Total ← Total + Mark
NEXT I
OUTPUT Total

مثال محلول. يجب على برنامج قراءة 5 درجات، ثم إخراج المجموع والمتوسط.

Total ← 0
FOR I ← 1 TO 5
    INPUT Mark
    Total ← Total + Mark
NEXT I
Average ← Total / 5
OUTPUT Total, Average

سطران يحملان الدرجات. Total ← 0 يجب أن يكون قبل الحلقة: ضعها داخلها وسيعيد المجموع تعيينه في كل مرور، لذا سيعرض البرنامج الدرجة الأخيرة فقط. وAverage ← Total / 5 يجب أن يكون بعد الحلقة، لأن المجموع غير مكتمل حتى يتم إضافة كل الدرجات. التهيئة قبل الحساب بعد - هذا الترتيب هو ما يختبره السؤال حقًا.

Vocabulary · ⁨مفردات⁩ Train · ⁨تدريب⁩
English العربية
totalling/ˈtəʊtəlɪŋ/ جمع المجموع الكلي
counting/ˈkaʊntɪŋ/ عدّ
remainder/rɪˈmeɪndə/ الباقي
nested statement/ˈnestɪd ˈsteɪtmənt/ عبارة متداخلة
8.1

Operators · ⁨العمليات⁩

English

Arithmetic operators

Operator Meaning
+ - * / add, subtract, multiply, divide
^ raised to the power of
MOD the remainder 余数 after division
DIV the whole-number part of a division

For example, 17 MOD 5 is 2, and 17 DIV 5 is 3.

Relational operators

These compare two values and give a Boolean result: =, <, <=, >, >=, and <> (not equal to).

Logical operators

These join conditions: AND (both must be true), OR (at least one must be true), NOT (reverses true/false).

العربية

العمليات الحسابية

العملية المعنى
+ - * / جمع، طرح، ضرب، قسمة
^ مرفوعة للأس
MOD الباقي بعد القسمة
DIV الجزء الصحيح من القسمة

على سبيل المثال، 17 MOD 5 هي 2، و17 DIV 5 هي 3.

العمليات النسبية

هذه تقارن قيمتين وتعطي نتيجة منطقية: =، <، <=، >، >=، و<> (لا يساوي).

العمليات المنطقية

هذه تربط الشروط: AND (يجب أن يكون كلاهما صحيحًا)، OR (يجب أن يكون أحدهما على الأقل صحيحًا)، NOT (يعكس صحيح/خاطئ).

ثلاث عائلات من المعاملات: المعاملات الحسابية مثل الجمع والضرب تعطي رقماً، المعاملات العلائقية مثل أصغر من تقارن وتعطي صحيحاً أو خطأً، المعاملات المنطقية AND OR NOT تربط الشروط
العائلات الثلاث من العمليات: الحسابية والنسبية والمنطقية
IF Age >= 13 AND Age <= 19
  THEN
    OUTPUT "Teenager"
ENDIF
8.1

String handling · ⁨التعامل مع السلاسل النصية⁩

English

A string is made of characters. Useful operations:

  • length 长度 — the number of characters in the string;
  • substring 子串 — a smaller part taken from the string;
  • upper case 大写 — change letters to capitals;
  • lower case 小写 — change letters to small letters.

(The first character may be counted as position 0 or position 1, depending on the language.)

العربية

السلسلة النصية تتكون من أحرف. عمليات مفيدة:

  • length — عدد الأحرف في السلسلة النصية;
  • substring — جزء أصغر مأخوذ من السلسلة النصية;
  • upper case — تحويل الأحرف إلى أحرف كبيرة;
  • lower case — تحويل الأحرف إلى أحرف صغيرة.
name ← "Computer"
OUTPUT LENGTH(name)          // 8
OUTPUT SUBSTRING(name, 1, 4) // "Comp"
OUTPUT UCASE(name)           // "COMPUTER"
OUTPUT LCASE(name)           // "computer"

(قد يُحسب أول حرف كموضع 0 أو موضع 1، اعتمادًا على اللغة.)

Explore · ⁨استكشف⁩

SUBSTRING: take part of a string

The first character is at position 1. SUBSTRING(Word, Start, Length) takes Length characters beginning at Start — drag the two handles and read the call it builds.

Vocabulary · ⁨مفردات⁩ Train · ⁨تدريب⁩
English العربية
substring/ˈsʌbstrɪŋ/ جزء من النص
upper case/ˈʌpə keɪs/ حرف كبير
lower case/ˈləʊə keɪs/ حرف صغير
8.1

Nested statements · ⁨الجمل المتداخلة⁩

English

A nested statement 嵌套语句 is one control structure placed inside another. You can nest selection and iteration.

You will not have to write more than three levels of nesting.

العربية

الجملة المتداخلة هي بنية تحكم واحدة موضوعة داخل أخرى. يمكنك تداخل الاختيار والتكرار.

FOR I ← 1 TO 3
    IF MOD(I, 2) = 0
      THEN
        OUTPUT I, " is even"
      ELSE
        OUTPUT I, " is odd"
    ENDIF
NEXT I

لن تضطر لكتابة أكثر من ثلاث مستويات من التداخل.

8.1

Procedures and functions · ⁨الإجراءات والدوال⁩

English

To avoid repeating code, you can break a program into named blocks.

  • A procedure 过程 is a named block of code that does a task. You run it with CALL.
  • A function 函数 is like a procedure, but it returns a value back to where it was called.

A parameter 参数 is a value passed into a procedure or function (up to three parameters).

Local and global variables

  • A local variable 局部变量 is declared inside a procedure or function. It can only be used there.
  • A global variable 全局变量 is declared in the main program. It can be used anywhere.

Local variables are safer, because they cannot be changed by mistake from another part of the program.

العربية

لتجنب تكرار الكود، يمكنك تقسيم البرنامج إلى كتل مسماة.

  • إجراء هو كتلة كود مسماة تقوم بمهمة. تشغله باستخدام CALL.
  • دالة تشبه الإجراء، لكنها تعيد قيمة إلى المكان الذي تم استدعاؤها منه.

المعامل هو قيمة تُمرر إلى إجراء أو دالة (حتى ثلاثة معاملات).

PROCEDURE Greet(PersonName : STRING)
    OUTPUT "Hello ", PersonName
ENDPROCEDURE

CALL Greet("Sam")
FUNCTION Square(N : INTEGER) RETURNS INTEGER
    RETURN N * N
ENDFUNCTION

Answer ← Square(5)   // answer is 25

المتغيرات المحلية والعالمية

  • متغير محلي يتم الإعلان عنه داخل إجراء أو دالة. يمكن استخدامه هناك فقط.
  • متغير عالمي يتم الإعلان عنه في البرنامج الرئيسي. يمكن استخدامه في أي مكان.

المتغيرات المحلية أكثر أمانًا، لأنها لا يمكن تغييرها عن طريق الخطأ من جزء آخر من البرنامج.

Vocabulary · ⁨مفردات⁩ Train · ⁨تدريب⁩
English العربية
procedure/prəˈsiːdʒə/ إجراء
function/ˈfʌŋkʃn/ دالة
parameter/pəˈræmɪtə/ معامل
local variable/ˈləʊkl ˈveərɪəbl/ متغير محلي
global variable/ˈɡləʊbl ˈveərɪəbl/ متغير عالمي
library routine/ˈlaɪbrəri ruːˈtiːn/ روتين المكتبة
maintainable/meɪnˈteɪnəbl/ قابل للصيانة
meaningful identifiers/ˈmiːnɪŋfl aɪˈdentɪfaɪəz/ مسميات ذات معنى
comments/ˈkɒments/ التعليقات
8.1

Library routines · ⁨الروتين المكتبي⁩

English

A library routine 库程序 is a ready-made piece of code you can use. You must know these:

Routine What it does
MOD gives the remainder of a division
DIV gives the whole-number part of a division
ROUND rounds a real number to a number of decimal places
RANDOM gives a random number
العربية

الروتين المكتبي هو قطعة كود جاهزة يمكنك استخدامها. يجب أن تعرف هذه:

الروتين ما يفعله
MOD يعطي باقي القسمة
DIV يعطي الجزء الصحيح من القسمة
ROUND يقرب عددًا حقيقيًا إلى عدد من المنازل العشرية
RANDOM يعطي عددًا عشوائيًا
8.1

Writing a maintainable program · ⁨كتابة برنامج قابل للصيانة⁩

English

A maintainable 可维护的 program is easy for other people to read and change later. To make one:

  • use meaningful identifiers 有意义的标识符 — clear names for variables, constants, arrays, procedures and functions (totalScore, not x);
  • add comments 注释 to explain what parts of the code do;
  • use procedures and functions to split the work into small blocks.
العربية

البرنامج القابل للصيانة سهل القراءة والتعديل لاحقًا من قبل الآخرين. لجعله:

  • استخدم معرفات ذات معنى — أسماء واضحة للمتغيرات والثوابت والمصفوفات والإجراءات والدوال (totalScore، وليس x);
  • أضف تعليقات لتوضيح ما تفعله أجزاء من الكود;
  • استخدم الإجراءات والدوال لتقسيم العمل إلى كتل صغيرة.
8.2

Arrays · ⁨المصفوفات⁩

Syllabus · ⁨المنهج⁩
English
Candidates should be able to: Notes and guidance
1 Declare and use one-dimensional (1D) and two-dimensional (2D) arrays
2 Understand the use of arrays • Including the use of variables as indexes in arrays
3 Write values into, and read values from, an array using iteration • The first index can be zero or one • Including nested iteration
العربية
يجب أن يكون المرشحون قادرين على: ملاحظات وإرشادات
1 عرّف واستخدم المصفوفات أحادية البعد (1D) والمصفوفات ثنائية البعد (2D)
2 افهم استخدام المصفوفات • بما في ذلك استخدام المتغيرات كمؤشرات في المصفوفات
3 اكتب قيمًا داخل مصفوفة واقرأ قيمًا منها باستخدام التكرار • يمكن أن يكون المؤشر الأول صفرًا أو واحدًا • بما في ذلك التكرار المتداخل

Source: Cambridge International syllabus · ⁨المصدر: منهج كامبريدج الدولي⁩

English

An array 数组 is a single variable that holds many values of the same type, found by an index 索引 (a position number).

One-dimensional arrays

A one-dimensional (1D) array 一维数组 is like a single list.

You can use a loop to fill or read an array:

Two-dimensional arrays

A two-dimensional (2D) array 二维数组 is like a table with rows and columns. It uses two indexes.

You read a 2D array with a loop inside a loop (nested iteration).

العربية

المصفوفة متغير واحد يحمل قيمًا متعددة من نفس النوع، يتم الوصول إليها عبر مؤشر (رقم موقع).

المصفوفات أحادية البعد

المصفوفة أحادية البعد (1D) تشبه قائمة واحدة.

DECLARE Scores : ARRAY[1:5] OF INTEGER
Scores[1] ← 90
Scores[2] ← 75
OUTPUT Scores[1]
خمس صناديق في صف واحد مُصنّفة بالمؤشر من 1 إلى 5، تحتوي على قيم، مع تظليل القيمة عند المؤشر 2 كـ 75
المصفوفة أحادية البعد (1D) تحتفظ بالعديد من القيم في متغير واحد؛ يتم العثور على كل قيمة عن طريق مؤشرها

يمكنك استخدام حلقة تكرار لملء مصفوفة أو قراءتها:

FOR I ← 1 TO 5
    INPUT Scores[I]
NEXT I

المصفوفات ثنائية الأبعاد

المصفوفة ثنائية الأبعاد (2D) تشبه جدولاً يحتوي على صفوف وأعمدة. تستخدم مؤشرين.

DECLARE Grid : ARRAY[1:3, 1:3] OF INTEGER
Grid[1, 1] ← 5
Grid[2, 3] ← 8
شبكة بحجم 3×3 مع صفوف وأعمدة مرقمة؛ الخلية الموجودة في الصف 2 والعمود 3 مظللة ومُصنّفة باسم الصف 2 العمود 3
المصفوفة 2D هي جدول؛ يتم العثور على كل قيمة باستخدام مؤشرين، [صف، عمود]

تقرأ مصفوفة 2D باستخدام حلقة داخل حلقة (تكرار متداخل).

Explore · ⁨استكشف⁩

Arrays

Pick a row and a column to read one cell. Cambridge arrays count from 1, and a 2-D element is written with ONE pair of brackets — Grid[2, 3].

Vocabulary · ⁨مفردات⁩ Train · ⁨تدريب⁩
English العربية
array/əˈreɪ/ المصفوفة (array)
index/ˈɪndeks/ فهرس
one-dimensional (1D) array/wʌn daɪˈmenʃənl əˈreɪ/ مصفوفة أحادية البعد (1D)
two-dimensional (2D) array/tuː daɪˈmenʃənl əˈreɪ/ مصفوفة ثنائية الأبعاد (2D)
8.3

File handling · ⁨التعامل مع الملفات⁩

Syllabus · ⁨المنهج⁩
English
Candidates should be able to: Notes and guidance
1 Understand the purpose of storing data in a file to be used by a program
2 Open, close and use a file for reading and writing • Including: – read and write single items of data – read and write a line of text
العربية
يجب أن يكون المرشحون قادرين على: ملاحظات وإرشادات
1 افهم الغرض من تخزين البيانات في ملف لاستخدامه بواسطة برنامج
2 افتح وأغلق واستخدم ملفًا للقراءة والكتابة • بما في ذلك: – قراءة وكتابة عنصر بيانات مفرد – قراءة وكتابة سطر نصي

Source: Cambridge International syllabus · ⁨المصدر: منهج كامبريدج الدولي⁩

English

A program can store data in a file 文件 so it is kept after the program stops. You must open the file, use it, then close it.

You can read and write single items of data or a whole line of text. Always close a file when you have finished with it.

العربية

يمكن للبرنامج تخزين البيانات في ملف بحيث تُحفظ بعد توقف البرنامج. يجب عليك فتح الملف، ثم استخدامه، وبعدها إغلاقه.

OPENFILE "data.txt" FOR WRITE
WRITEFILE "data.txt", "Hello"
CLOSEFILE "data.txt"

OPENFILE "data.txt" FOR READ
READFILE "data.txt", Line
CLOSEFILE "data.txt"

يمكنك قراءة وكتابة عناصر بيانات فردية أو سطر كامل من النصوص. قم دائماً بإغلاق الملف عند الانتهاء منه.

Vocabulary · ⁨مفردات⁩ Train · ⁨تدريب⁩
English العربية
file/faɪl/ ملف
8.3

Exam tips · ⁨نصائح للامتحان⁩

English
  • A variable can change while the program runs; a constant is fixed. Learn the five data types: integer, real, char, string, Boolean.
  • Every program is built from three structures: sequence, selection (IF / CASE), and iteration (loops).
  • A WHILE loop tests before the body, so it may run zero times; a REPEAT … UNTIL loop tests after, so it always runs at least once.
  • MOD gives the remainder and DIV the whole-number part of a division: 17 MOD 5 is 2, 17 DIV 5 is 3.
  • A function returns a value; a procedure does not. A local variable works only inside its block; a global one works anywhere.
العربية
  • المتغير يمكن أن يتغير أثناء تشغيل البرنامج؛ أما الثابت فهو ثابت. تعلم أنواع البيانات الخمسة: عدد صحيح، عدد حقيقي، حرف، نص، منطقي.
  • يُبنى كل برنامج من ثلاث هياكل: التسلسل، والاختيار (IF / CASE)، والتكرار (الحلقات).
  • حلقة WHILE تختبر قبل الجسم، لذا قد لا تعمل أبداً؛ أما حلقة REPEAT … UNTIL فتختبر بعد، لذا تعمل دائماً مرة واحدة على الأقل.
  • MOD يعطي الباقي وDIV الجزء الصحيح للقسمة: 17 MOD 5 يساوي 2، و17 DIV 5 يساوي 3.
  • الدالة تُرجع قيمة؛ أما الإجراء فلا. المتغير المحلي يعمل فقط داخل كتلته؛ بينما المتغير العالمي يعمل في أي مكان.

Interactive lessons on this topic · ⁨دروس تفاعلية حول هذا الموضوع⁩

Work through it step by step, with instant-check exercises. · ⁨ا-working عليه خطوة بخطوة، مع تمارين تحقق فوري.⁩

Past Papers · ⁨أوراق الامتحانات السابقة⁩

More topics in IGCSE Computer Science · ⁨IGCSE علوم الحاسوب⁩ · ⁨المزيد من المواضيع في IGCSE Computer Science · ⁨IGCSE علوم الحاسوب⁩⁩

Log in or create account · ⁨تسجيل الدخول أو إنشاء حساب⁩

IGCSE, A-Level & AP