📚 Programming Fundamentals for CCEA IGCSE Computer Science | CCEA IGCSE 计算机编程基础考点精讲
Programming is the process of writing instructions that a computer can execute. For CCEA IGCSE Computer Science, mastering the fundamentals means understanding how to break down problems, use the right data types, control the flow of execution, and write clean, efficient code. This guide covers all the essential concepts you need to know, from variables and operators to subprograms and debugging.
编程是编写计算机可执行指令的过程。对于 CCEA IGCSE 计算机科学来说,掌握编程基础意味着理解如何分解问题、使用正确的数据类型、控制执行流程并编写清晰高效的代码。本指南涵盖了你需要掌握的所有核心概念,从变量和运算符到子程序和调试。
1. Variables and Data Types | 变量与数据类型
A variable is a named storage location in memory that holds a value which can change during program execution. Before using a variable, you must declare it with a name and a data type.
变量是内存中一个命名的存储位置,它保存的值在程序执行期间可以改变。在使用变量之前,必须用名称和数据类型声明它。
Common data types include Integer (whole numbers), Real/Float (numbers with decimals), Boolean (TRUE or FALSE), Character (a single letter, digit or symbol), and String (a sequence of characters). Choosing the right data type is important because it affects memory usage and the operations you can perform.
常见的数据类型包括整型(整数)、实型/浮点型(带小数的数值)、布尔型(TRUE 或 FALSE)、字符型(单个字母、数字或符号)以及字符串(字符序列)。选择正确的数据类型很重要,因为它会影响内存使用和可执行的操作。
Variables should be given meaningful names that follow the rules of the programming language. For example, a variable storing a student’s age could be named studentAge. CCEA pseudocode often uses an assignment arrow ← to assign values, e.g., age ← 16.
变量应使用有意义的名称,并遵循编程语言的命名规则。例如,存储学生年龄的变量可命名为 studentAge。CCEA 伪代码通常使用赋值箭头 ← 进行赋值,如 age ← 16。
2. Constants and Literals | 常量与字面量
A constant is similar to a variable, but its value cannot be changed once it has been set. Constants are used for values that remain the same throughout the program, such as mathematical π (pi) or the number of days in a week.
常量类似于变量,但它的值一旦设定就不能更改。常量用于整个程序中保持不变的值,例如数学 π(圆周率)或一周的天数。
Using constants makes code easier to read and update. If a value needs to change, you only modify the constant declaration rather than searching for every occurrence. A literal is a value that is written directly into the code, like 100 or “Hello”.
使用常量使代码更易阅读和更新。如果某个值需要改变,只需修改常量声明,而不必搜索每一处出现的地方。字面量是直接写入代码的值,如 100 或 “Hello”。
3. Input and Output | 输入与输出
Programs need to interact with the user: input allows the user to supply data, while output displays information on the screen. In CCEA pseudocode, INPUT reads data from the keyboard, and OUTPUT (or PRINT) sends data to the display.
程序需要与用户交互:输入允许用户提供数据,输出则将信息显示在屏幕上。在 CCEA 伪代码中,INPUT 从键盘读取数据,OUTPUT(或 PRINT)将数据发送到显示器。
Example: OUTPUT “Enter your name: “ followed by INPUT userName. The variable userName will then store what the user typed. Efficient I/O design ensures the user knows what is expected.
例如:OUTPUT “Enter your name: “,然后 INPUT userName。变量 userName 将存储用户键入的内容。高效的输入输出设计能确保用户清楚预期。
4. Sequence, Selection, Iteration | 顺序、选择、迭代
Every program is built from three basic control structures: sequence (executing instructions in order), selection (making decisions), and iteration (repeating code). These structures are the foundation of structured programming.
每个程序都建立在三种基本控制结构之上:顺序(按顺序执行指令)、选择(做出决策)以及迭代(重复代码)。这些结构是结构化编程的基础。
Sequence is the default flow: one statement after another. Selection uses IF…THEN…ELSE (or CASE statements) to choose different paths. Iteration uses loops like WHILE…DO, REPEAT…UNTIL, or FOR…NEXT to repeat a block of code until a condition is met.
顺序是默认流程:一条语句接一条语句。选择使用 IF…THEN…ELSE(或 CASE 语句)来选择不同路径。迭代使用 WHILE…DO、REPEAT…UNTIL 或 FOR…NEXT 等循环重复执行一段代码,直到满足条件。
5. Arithmetic and Relational Operators | 算术与关系运算符
Arithmetic operators perform mathematical calculations: + (addition), – (subtraction), * (multiplication), / (division), ^ (exponentiation) and MOD (modulus, the remainder after division). For example, 7 MOD 3 gives 1.
算术运算符执行数学运算:+(加)、-(减)、*(乘)、/(除)、^(幂)和 MOD(模运算,除法后的余数)。例如,7 MOD 3 的结果是 1。
Relational operators compare two values and return a Boolean result. They include = (equal to), ≠ (not equal to), > (greater than), < (less than), ≥ (greater than or equal to), and ≤ (less than or equal to). These are used in selection and loop conditions.
关系运算符比较两个值并返回布尔结果。它们包括 =(等于)、≠(不等于)、>(大于)、<(小于)、≥(大于或等于)和 ≤(小于或等于)。这些运算符用于选择和循环条件中。
6. Boolean Logic | 布尔逻辑
Boolean logic deals with TRUE/FALSE values using operators AND, OR, and NOT. In CCEA, these can be written as AND, OR, NOT in pseudocode. They help build complex conditions.
布尔逻辑使用 AND、OR 和 NOT 运算符处理 TRUE/FALSE 值。在 CCEA 伪代码中,可写为 AND、OR、NOT。它们帮助构建复杂条件。
AND returns TRUE only if both operands are TRUE; OR returns TRUE if at least one operand is TRUE; NOT reverses the Boolean value. A truth table shows all possible combinations. Understanding operator precedence is also vital: NOT is evaluated first, then AND, then OR, unless parentheses are used to override this order.
AND 只有两个操作数都为 TRUE 时才返回 TRUE;OR 只要至少一个操作数为 TRUE 就返回 TRUE;NOT 反转布尔值。真值表显示所有可能组合。理解运算符优先级也至关重要:首先计算 NOT,然后是 AND,最后是 OR,除非使用括号改变顺序。
7. String Manipulation | 字符串操作
Strings are sequences of characters. Common operations include concatenation (joining two strings together using + or &), determining the length of a string (LEN), extracting substrings (SUBSTRING), and converting case (UPPER, LOWER).
字符串是字符序列。常见操作包括连接(使用 + 或 & 将两个字符串连接起来)、确定字符串长度(LEN)、提取子串(SUBSTRING)以及转换大小写(UPPER、LOWER)。
In CCEA pseudocode, you might see LENGTH(string) and SUBSTRING(string, start, length). For example, SUBSTRING(“Computer”, 1, 3) returns “Com”. Understanding how to index characters (often starting at 1) is important for exam questions.
在 CCEA 伪代码中,你可能会见到 LENGTH(string) 和 SUBSTRING(string, start, length)。例如,SUBSTRING(“Computer”, 1, 3) 返回 “Com”。理解字符索引(通常从 1 开始)对考试题目很重要。
8. Arrays and Lists | 数组与列表
An array is a data structure that can hold multiple values of the same data type under a single identifier. Each element is accessed via an index, usually starting at 0 or 1 depending on the language (CCEA pseudocode often uses 1-based indexing).
数组是一种数据结构,可以在一个标识符下保存多个相同数据类型的值。每个元素通过索引访问,根据语言不同,索引通常从 0 或 1 开始(CCEA 伪代码通常使用从 1 开始的索引)。
One-dimensional arrays are like a list. You declare them with a size, e.g., DECLARE scores[5]. Two-dimensional arrays are like tables with rows and columns. Iterating through arrays using FOR loops is a common examination task. Remember to check boundaries to avoid index errors.
一维数组就像列表。你可以声明它们的大小,如 DECLARE scores[5]。二维数组类似于有行和列的表格。使用 FOR 循环遍历数组是常见的考试任务。记住检查边界以避免索引错误。
9. Subprograms: Functions and Procedures | 子程序:函数与过程
Subprograms are named blocks of code that perform a specific task. They promote reusability and make programs easier to debug. There are two types: functions (which return a value) and procedures (which perform an action but do not necessarily return a value).
子程序是执行特定任务的命名代码块。它们提高了代码复用性,使程序更容易调试。有两种类型:函数(返回值)和过程(执行操作但不一定返回值)。
A function is called as part of an expression, e.g., result ← CalculateArea(length, width). A procedure is called as a standalone statement, e.g., DisplayMenu(). Parameters pass data into subprograms; they can be passed by value or by reference. CCEA pseudocode uses RETURN to send back a value from a function.
函数作为表达式的一部分调用,如 result ← CalculateArea(length, width)。过程作为独立语句调用,如 DisplayMenu()。参数将数据传入子程序;它们可以按值传递或按引用传递。CCEA 伪代码使用 RETURN 从函数返回一个值。
10. Scope of Variables | 变量作用域
The scope of a variable refers to the part of the program where the variable is accessible. Local variables are declared inside a subprogram and can only be used there. Global variables are declared at the top of the program and can be used anywhere.
变量的作用域指程序中可以访问该变量的部分。局部变量在子程序内部声明,只能在那里使用。全局变量在程序顶部声明,可在任何地方使用。
It is considered good practice to use local variables where possible, as global variables can lead to unintended side effects and make programs harder to understand. In CCEA questions, you may be asked to identify which variable is in scope at a given point.
尽可能使用局部变量被认为是良好实践,因为全局变量可能导致意外的副作用并使程序难以理解。在 CCEA 考题中,你可能需要识别给定位置上哪个变量在作用域内。
11. Debugging and Testing | 调试与测试
Debugging is the process of finding and fixing errors (bugs) in a program. Syntax errors occur when the code does not follow the language’s rules; logic errors cause the program to behave incorrectly; runtime errors happen during execution (e.g., division by zero).
调试是查找并修复程序中的错误(漏洞)的过程。语法错误发生在代码不遵循语言规则时;逻辑错误导致程序行为不正确;运行时错误在执行期间发生(例如除以零)。
Testing involves running the program with carefully chosen data to ensure it works correctly. Test plans should include normal data, boundary data (values at the limits), and erroneous data. Trace tables are used to manually step through the values of variables to find logic errors.
测试包括使用精心选择的数据运行程序,以确保其正常工作。测试计划应包括正常数据、边界数据(极限值)和错误数据。跟踪表用于手动逐步跟踪变量值以查找逻辑错误。
12. Programming Style and Comments | 编程风格与注释
Writing clear, readable code is essential. Good programming style includes meaningful identifier names, consistent indentation, and the use of comments to explain the purpose of code without affecting execution. In CCEA pseudocode, comments are often written after //.
编写清晰、可读的代码至关重要。良好的编程风格包括有意义的标识符名称、一致的缩进,以及使用注释在不影响执行的情况下解释代码目的。在 CCEA 伪代码中,注释通常写在 // 之后。
Proper indentation visually represents the structure of the program, especially inside selection and iteration blocks. Comments should not state the obvious but clarify why a particular approach was taken. Examiners look for these elements when awarding marks for solution design.
适当的缩进可以直观地表示程序结构,尤其是在选择和迭代块内部。注释不应陈述显而易见的内容,而应阐明为何采用某种特定方法。评分员在给解决方案设计打分时会关注这些要素。
Published by TutorHao | Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)