📚 IB Edexcel Computer Science: Laboratory Practical Guide | IB Edexcel 计算机:实验操作指南
Hands-on experimentation is the cornerstone of mastering computer science. Whether you are following the IB Diploma curriculum or the Edexcel specification, practical lab work builds the problem‑solving skills, algorithmic thinking, and technical fluency required for internal assessments, projects, and final examinations. This guide walks you through a structured series of lab activities, from setting up your development environment to advanced topics such as socket programming and microcontroller interfacing.
动手实验是掌握计算机科学的基石。无论您遵循 IB 文凭课程还是 Edexcel 考试大纲,实验室操作都能培养解决问题、算法思维和技术熟练度,这些能力对于内部评估、项目作业和最终考试都至关重要。本指南将带您完成一系列结构化的实验活动,涵盖从搭建开发环境到套接字编程和微控制器接口等高级主题。
1. Setting Up the Development Environment | 搭建开发环境
A reliable toolchain is essential for efficient coding experiments. For general‑purpose programming, install Python 3.10+ from the official website, making sure to add it to your system PATH. For Java (often required in IB and Edexcel A‑Level), download the latest JDK and set up JAVA_HOME. A lightweight IDE such as VS Code with appropriate extensions (Python, Java Extension Pack, SQLite Viewer) works well. For microcontroller labs, install the Arduino IDE and any necessary board drivers.
一个可靠的工具链对于高效的编码实验至关重要。对于通用编程,请从官方网站安装 Python 3.10 或更高版本,务必将其添加到系统 PATH 中。对于 Java(IB 和 Edexcel A‑Level 经常需要),请下载最新的 JDK 并设置 JAVA_HOME。使用轻量级 IDE(例如安装适当扩展的 VS Code,如 Python、Java Extension Pack、SQLite Viewer)效果很好。对于微控制器实验,请安装 Arduino IDE 及所需的板卡驱动。
Create a dedicated folder structure for your labs, such as /cs_labs/week_01, and initialise a Git repository to track changes. Familiarise yourself with the terminal commands for compiling and running programs: python3 main.py, javac Main.java && java Main. These habits will mirror professional development practices and prepare you for the IB Computer Science IA documentation.
为您的实验创建一个专用的文件夹结构,例如 /cs_labs/week_01,并初始化 Git 仓库以跟踪更改。熟悉用于编译和运行程序的终端命令:python3 main.py、javac Main.java && java Main。这些习惯将反映专业开发实践,并为您撰写 IB 计算机科学内部评估文档做好准备。
2. Basic I/O and Data Types | 基本输入输出与数据类型
Begin with the fundamental building blocks: accepting user input and displaying output. In Python, use input() and print(); in Java, the Scanner class and System.out.println(). Understand the native types such as int, float, char, String, and Boolean, and how type casting works. For example, converting a string input to an integer requires Integer.parseInt() in Java or int() in Python. Always handle potential exceptions like NumberFormatException or ValueError.
从基本的构建模块开始:接收用户输入和显示输出。在 Python 中使用 input() 和 print();在 Java 中使用 Scanner 类和 System.out.println()。理解 int、float、char、String 和 Boolean 等原生类型,以及类型转换的工作原理。例如,将字符串输入转换为整数需要在 Java 中使用 Integer.parseInt(),在 Python 中使用 int()。务必处理潜在的异常,如 NumberFormatException 或 ValueError。
Lab task: write a program that asks for a user’s name, age, and height, then outputs a formatted summary. Extend this to perform arithmetic operations on the inputs, such as calculating the year of birth. Focus on robust input validation—reject non‑numeric values gracefully. Document your code with comments explaining each step, as this will become invaluable for the IB solution commentary.
实验任务:编写一个程序,询问用户的姓名、年龄和身高,然后输出格式化的摘要。扩展该程序,对输入执行算术运算,例如计算出生年份。注重健壮的输入验证——优雅地拒绝非数值输入。用注释记录代码,解释每一步,这对于 IB 解决方案说明将非常宝贵。
3. Control Structures in Action | 控制结构实战
Conditional statements (if-else, switch‑case) and loops (for, while, do‑while) form the logic core of any algorithm. In Java, remember that switch expressions can accept String values (since Java 7) and that the break keyword prevents fall‑through. Python relies on elif and indentation instead of braces. Implement a simple grade calculator: input a numeric score and output the corresponding letter grade based on a defined scale (e.g., 90‑100 = A*, 80‑89 = A, etc.).
条件语句(if-else、switch‑case)和循环(for、while、do‑while)构成了任何算法的逻辑核心。在 Java 中,请记住 switch 表达式可以接受 String 值(自 Java 7 起),而 break 关键字可防止穿透。Python 依赖 elif 和缩进,而非大括号。实现一个简单的成绩计算器:输入数值分数,根据定义的等级标准(例如 90‑100 = A*,80‑89 = A 等)输出相应的字母等级。
Next, simulate a number‑guessing game using a while loop with a random target number (using java.util.Random or Python’s random.randint). Count attempts and provide hints (higher/lower). This exercise reinforces loop termination conditions and the importance of updating control variables. For Edexcel’s programming project, such logic must be explained using pseudocode or flowcharts.
接下来,使用 while 循环模拟一个猜数字游戏,目标数字随机生成(使用 java.util.Random 或 Python 的 random.randint)。统计猜测次数并提供提示(高一些/低一些)。该练习强化了循环终止条件以及更新控制变量的重要性。对于 Edexcel 的编程项目,必须使用伪代码或流程图来解释此类逻辑。
4. Working with Arrays and Lists | 数组与列表操作
Data structures store and organise information. In Java, you will use fixed‑size arrays (int[] arr = new int[10]) and the ArrayList class for dynamic resizing. Python offers lists, which are inherently dynamic. Explore common operations: traversal, insertion, deletion, searching (linear and binary), and sorting. Implement a linear search on an unsorted array by iterating and comparing each element until a match is found.
数据结构用于存储和组织信息。在 Java 中,您将使用固定大小的数组(int[] arr = new int[10])和用于动态调整大小的 ArrayList 类。Python 提供了本质上是动态的列表。探索常见操作:遍历、插入、删除、搜索(线性查找和二分查找)以及排序。通过迭代并比较每个元素直到找到匹配项,在未排序数组上实现线性查找。
For binary search, first sort the array (using Arrays.sort() in Java or list.sort() in Python). Highlight the pre‑condition that the list must be ordered. Measure the number of comparisons in both searches for a worst‑case target, linking to the Big O notation. In IB exams, comparing O(n) vs O(log n) is a recurring theme. Edexcel requires students to understand the efficiency of standard algorithms.
对于二分查找,首先对数组进行排序(Java 中使用 Arrays.sort(),Python 中使用 list.sort())。强调必须满足列表有序这一前提条件。在最坏情况下测量两种查找的比较次数,并与大 O 表示法相关联。在 IB 考试中,比较 O(n) 和 O(log n) 是一个反复出现的主题。Edexcel 要求学生理解标准算法的效率。
5. Functions and Modular Programming | 函数与模块化编程
Breaking a problem into reusable functions is a key abstraction skill. Define functions with parameters and return values, distinguishing between pass‑by‑value (Java primitives) and pass‑by‑reference (Java objects, Python list references). Create a utility module that contains functions for mathematical operations such as factorial (using recursion), greatest common divisor (Euclidean algorithm), and prime checker.
将问题分解为可重用的函数是一项关键的抽象技能。定义带有参数和返回值的函数,区分值传递(Java 基本类型)和引用传递(Java 对象,Python 列表引用)。创建一个实用模块,其中包含用于数学运算的函数,例如阶乘(使用递归)、最大公约数(欧几里德算法)和质数检查器。
Write a test harness that calls each function with diverse inputs, including edge cases (0, negative numbers, very large values). Use assertions to verify correctness automatically. For Java, include Javadoc comments; for Python, docstrings. The IB internal assessment highly rewards well‑documented, modular code, while Edexcel’s NEA (Non‑Exam Assessment) demands evidence of structured programming.
编写一个测试框架,使用多样化输入调用每个函数,包括边界情况(0、负数、非常大的值)。使用断言自动验证正确性。对于 Java,加入 Javadoc 注释;对于 Python,加入文档字符串。IB 内部评估高度认可文档完善、模块化的代码,而 Edexcel 的非考试评估(NEA)要求提供结构化编程的证据。
6. File Handling and Data Persistence | 文件处理与数据持久化
Reading from and writing to files is essential for any data‑driven application. In Python, use the open() context manager (‘r’, ‘w’, ‘a’ modes); in Java, BufferedReader/BufferedWriter or the modern Files.readAllLines() method. Pay attention to file paths (relative vs absolute) and exception handling (FileNotFoundException, IOException). Construct a log‑file writer that appends timestamped entries to a text file.
从文件读取和写入对于任何数据驱动的应用程序都是必不可少的。在 Python 中,使用 open() 上下文管理器(’r’、’w’、’a’ 模式);在 Java 中,使用 BufferedReader/BufferedWriter 或现代的 Files.readAllLines() 方法。注意文件路径(相对路径与绝对路径)和异常处理(FileNotFoundException、IOException)。构建一个日志文件写入器,将带时间戳的条目追加到文本文件中。
Process a CSV dataset, such as student grades, using a library (Python’s csv module, Java’s OpenCSV). Calculate average, minimum, and maximum scores and write the summary back to a new file. This directly links to the Edexcel component on data management and the IB HL topic of abstract data structures, where flat files serve as a backing store for simple databases.
使用库(Python 的 csv 模块,Java 的 OpenCSV)处理 CSV 数据集,例如学生成绩。计算平均分、最低分和最高分,并将摘要写回新文件。这直接关联到 Edexcel 的数据管理专题和 IB 高级课程的抽象数据结构主题,其中平面文件可作为简单数据库的后端存储。
7. Database Queries with SQL | 使用 SQL 进行数据库查询
Set up a lightweight relational database using SQLite (built into Python, or via JDBC in Java). Create tables with appropriate data types (INTEGER, TEXT, REAL) and constraints (PRIMARY KEY, NOT NULL). Populate the tables with sample records and then practise key SQL statements: SELECT with WHERE, ORDER BY, GROUP BY and HAVING, as well as multi‑table JOINs.
使用 SQLite(Python 内置,或 Java 通过 JDBC)建立轻量级关系数据库。创建具有适当数据类型(INTEGER、TEXT、REAL)和约束(PRIMARY KEY、NOT NULL)的表。向表中插入示例记录,然后练习关键的 SQL 语句:带有 WHERE、ORDER BY、GROUP BY 和 HAVING 的 SELECT,以及多表连接 JOIN。
| SQL Clause | Purpose |
|---|---|
| SELECT * FROM Students WHERE Grade>=80 | Filter records (行列筛选) |
| SELECT City, COUNT(*) FROM Students GROUP BY City | Aggregate by group |
| SELECT * FROM Orders INNER JOIN Customers ON Orders.CustID=Customers.ID | Combine tables |
For IB, understanding the relational model and normalisation (1NF, 2NF, 3NF) is critical. Edexcel also tests SQL syntax in the examination. Document your schema design using an entity-relationship diagram (ERD) and explain how primary/foreign keys enforce referential integrity.
对于 IB 而言,理解关系模型和规范化(1NF、2NF、3NF)至关重要。Edexcel 考试也会考查 SQL 语法。使用实体关系图(ERD)记录您的模式设计,并解释主键/外键如何强制参照完整性。
8. Object-Oriented Programming Essentials | 面向对象编程基础
OOP is central to both IB and Edexcel curricula. Define a class (e.g., BankAccount) with private attributes (balance) and public methods (deposit, withdraw). Implement constructors, getters, and setters. Demonstrate encapsulation by preventing direct balance modification from outside the class. In Java, use the private keyword; in Python, prefix attributes with a double underscore for name mangling.
面向对象编程是 IB 和 Edexcel 课程的核心。定义一个类(例如 BankAccount),包含私有属性(balance)和公共方法(deposit、withdraw)。实现构造方法、访问器和修改器。通过禁止从类外部直接修改余额来展示封装性。在 Java 中使用 private 关键字;在 Python 中,为属性添加双下划线前缀以实现名称改写。
Extend the design with inheritance: a SavingsAccount subclass that adds an interest rate and overrides the withdraw method to enforce a minimum balance. Use polymorphism by storing both account types in a list and iterating to display their details. This mirrors the IB option D (OOP) requirements and Edexcel’s emphasis on code reuse and maintainability.
通过继承扩展设计:创建一个 SavingsAccount 子类,添加利率属性并重写 withdraw 方法以强制最低余额。利用多态性,将两种账户类型存储在列表中,并迭代显示其详细信息。这符合 IB 选项 D(面向对象编程)的要求,也契合 Edexcel 对代码重用和可维护性的重视。
9. Algorithm Efficiency: Timing Experiments | 算法效率:计时实验
Empirical measurement offers intuition about time complexity. Implement two sorting algorithms—bubble sort (O(n²)) and merge sort (O(n log n))—and time their execution on random arrays of increasing size. In Python, use the time.perf_counter() function; in Java, System.nanoTime(). Run each trial multiple times and record the average duration in a table.
经验测量有助于直观理解时间复杂度。实现两种排序算法——冒泡排序(O(n²))和归并排序(O(n log n))——并在逐渐增大的随机数组上计时执行。在 Python 中使用 time.perf_counter() 函数;在 Java 中使用 System.nanoTime()。多次运行每次试验,并将平均持续时间记录在表格中。
| n (elements) | Bubble Sort (ms) | Merge Sort (ms) |
|---|---|---|
| 100 | 0.2 | 0.1 |
| 1000 | 15 | 1.5 |
| 10000 | 1050 | 20 |
Plot the results on a graph (using matplotlib or a spreadsheet) to visualise the quadratic vs linearithmic growth. Discuss why constant factors and hardware can affect raw times but the asymptotic trend remains consistent. Both IB and Edexcel examinations require you to evaluate the suitability of algorithms based on their Big O classifications.
将结果绘制在图表上(使用 matplotlib 或电子表格),以直观展示二次增长与线性对数增长的对比。讨论为什么常数因子和硬件会影响原始时间,但渐近趋势保持一致。IB 和 Edexcel 考试都要求您根据大 O 分类评估算法的适用性。
10. Network Communication with Sockets | 基于套接字的网络通信
Understanding the client‑server model is vital for the networking topics. Write a simple TCP socket server in Python (using the socket module) that listens on localhost port 5000 and echoes back any received message in uppercase. Develop a corresponding client that connects to the server, sends a user‑typed string, and prints the response. In Java, you can use ServerSocket and Socket classes.
理解客户端‑服务器模型对于网络专题至关重要。用 Python 编写一个简单的 TCP 套接字服务器(使用 socket 模块),监听 localhost 端口 5000,并将收到的任何消息以大写形式回显。开发一个相应的客户端,连接到服务器,发送用户输入的字符串并打印响应。在 Java 中,您可以使用 ServerSocket 和 Socket 类。
Extend the lab by implementing a multi‑threaded server that can handle multiple clients simultaneously using threading.Thread or Java’s ExecutorService. Capture network traffic using Wireshark to observe the TCP three‑way handshake (SYN, SYN‑ACK, ACK). This practical exploration ties directly to the IB HL core “Network fundamentals” and the Edexcel specification’s coverage of protocols and the TCP/IP stack.
实现一个多线程服务器以扩展实验,该服务器可以使用 threading.Thread 或 Java 的 ExecutorService 同时处理多个客户端。使用 Wireshark 捕获网络流量,观察 TCP 三次握手(SYN、SYN‑ACK、ACK)。这一实践探索直接与 IB 高级课程核心“网络基础”以及 Edexcel 大纲中有关协议和 TCP/IP 协议栈的内容相关联。
11. Microcontroller Interfacing | 微控制器接口实验
For embedded systems sections, connect an Arduino Uno to a breadboard with LEDs, a push button, and a potentiometer. Write a sketch that reads the analog value from the potentiometer (0‑1023) and maps it to the brightness of an LED using PWM (analogWrite). Additionally, light up a different LED when the button is pressed, implementing digital I/O and debouncing.
针对嵌入式系统部分,将 Arduino Uno 连接到面包板,上面有 LED、按钮和电位器。编写一个草图,读取电位器的模拟值(0‑1023),并使用 PWM(analogWrite)将其映射到 LED 的亮度。另外,当按下按钮时点亮另一个 LED,实现数字 I/O 和去抖动处理。
Document the circuit diagram using standard symbols (Fritzing or hand‑drawn) and explain the role of the microcontroller’s ADC (analog‑to‑digital converter). This satisfies the IB Computer Science topic “Computer architecture” and the Edexcel practical requirement where students must demonstrate interaction between hardware and software. Modify the code to send sensor data over serial communication to a PC for logging.
使用标准符号(Fritzing 或手绘)记录电路图,并解释微控制器 ADC(模数转换器)的作用。这满足了 IB 计算机科学“计算机体系结构”主题的要求,也满足了 Edexcel 的实践要求,即学生必须展示硬件与软件之间的交互。修改代码,将传感器数据通过串行通信发送到 PC 进行记录。
12. Debugging and Testing Strategies | 调试与测试策略
Effective debugging reduces development time and improves code quality. Learn to use integrated debuggers in VS Code or IntelliJ: set breakpoints, step into/over code, inspect variable values, and evaluate expressions on the fly. For Python, pdb or the simpler breakpoint() function is helpful. Reproduce a common bug such as an off‑by‑one error in a loop and use the debugger to trace its execution.
有效的调试可以缩短开发时间并提高代码质量。学习使用 VS Code 或 IntelliJ 中的集成调试器:设置断点、单步执行(步入/步过)代码、检查变量值以及即时计算表达式。对于 Python,pdb 或更简单的 breakpoint() 函数很有帮助。重现一个常见的错误,例如循环中的差一错误,并使用调试器跟踪其执行过程。
Adopt a testing discipline: write unit tests for your functions using Python’s unittest or Java’s JUnit. Cover normal, boundary, and erroneous inputs. For the Edexcel NEA, evidence of testing with a plan‑do‑review cycle is required. For the IB IA, an extensive test table with expected and actual outcomes must be submitted. A systematic approach to validation demonstrates professional competency.
采用测试纪律:使用 Python 的 unittest 或 Java 的 JUnit 为函数编写单元测试。覆盖正常、边界和错误输入。对于 Edexcel 非考试评估,需要提供带有计划‑执行‑审查循环的测试证据。对于 IB 内部评估,必须提交一份详尽的测试表格,包含预期结果和实际结果。系统化的验证方法展示了专业能力。
Published by TutorHao | Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导