A-Level Computer Science Practical Lab Guide | A-Level 计算机实验操作指南

📚 A-Level Computer Science Practical Lab Guide | A-Level 计算机实验操作指南

Practical experiments form the core of A-Level Computer Science, enabling you to apply theoretical concepts to real-world scenarios. This guide walks you through setting up a safe, productive lab environment and performing key experiments in programming, data structures, algorithms, databases, networking and logic design.

实际操作是 A-Level 计算机科学的核心,帮助你从理论走向实践。本指南将带你建立安全高效的实验环境,并完成编程、数据结构、算法、数据库、网络和逻辑设计中的关键实验。

1. Lab Safety and Ethics | 实验安全与伦理

Always follow ethical guidelines when conducting computer science experiments. Never attempt to access systems, networks or data without explicit permission. Only use your own equipment or authorised lab resources, and keep all software legally licensed.

进行计算机科学实验时务必遵守道德准则。未经明确许可,绝不尝试访问系统、网络或数据。只使用自己的设备或已授权的实验资源,并确保所有软件均为合法授权。

Respect data privacy. If your experiment involves personal or sensitive data, anonymise it completely. Never share, publish or store real user credentials, even in test databases.

尊重数据隐私。若实验涉及个人或敏感数据,必须完全匿名化处理。即使在测试数据库中,也绝不要共享、发布或存储真实用户凭据。

When simulating network attacks or security flaws, operate exclusively within isolated virtual machines or sandboxes. Never target live systems, and always restore clean states after testing.

模拟网络攻击或安全漏洞时,务必在隔离的虚拟机或沙箱环境中操作。切勿以真实系统为目标,测试后始终恢复干净的环境状态。


2. Setting Up Your Programming Environment | 设置编程环境

Download and install the latest stable version of Python from python.org, or install Java JDK from adoptium.net. Ensure the interpreter or compiler is added to your system PATH so you can run programs from the terminal.

从 python.org 下载并安装最新稳定版 Python,或从 adoptium.net 安装 Java JDK。确保解释器或编译器已添加到系统 PATH,以便在终端中直接运行程序。

Choose an integrated development environment (IDE) suited to your language and syllabus. For Python, Thonny or VS Code are excellent starting points; for Java, BlueJ or IntelliJ IDEA Community Edition work well.

选择适合你语言和考试大纲的集成开发环境 (IDE)。Python 推荐 Thonny 或 VS Code;Java 推荐 BlueJ 或 IntelliJ IDEA Community Edition。

Verify your setup by creating a new project, writing a short program such as printing ‘Hello, World!’, and running it. Check that any required packages (e.g. unittest, sqlite3, matplotlib) can be imported without errors.

通过新建项目、编写如输出 “Hello, World!” 的简短程序并运行,验证环境是否配置成功。确保所需包 (如 unittest、sqlite3、matplotlib) 可以正常导入。


3. Using an IDE for Development | 使用集成开发环境

Learn the main areas of your IDE: the editor pane, project explorer, terminal/output console and debug toolbar. Customise the layout to keep your focus on code while having quick access to run and debug buttons.

熟悉 IDE 的主要区域:编辑区、项目浏览器、终端/输出控制台和调试工具栏。自定义布局,让编程时专注于代码,同时可以快速点击运行和调试按钮。

Use syntax highlighting and code completion to reduce typing errors. Most IDEs highlight variables, keywords and strings in distinct colours, and offer smart suggestions as you type.

利用语法高亮和代码补全减少输入错误。多数 IDE 会以不同颜色显示变量、关键字和字符串,并在你输入时给出智能提示。

Set up shortcut keys for common actions: Run (F5 or Ctrl+F5), Comment/Uncomment (Ctrl+/), and Reformat code. These significantly speed up your workflow during practical lab sessions.

为常用操作设置快捷键:运行 (F5 或 Ctrl+F5)、注释/取消注释 (Ctrl+/) 和格式化代码。这能大幅提升你在实验课上的工作效率。


4. Debugging Techniques | 调试技术

When your program behaves unexpectedly, use print statements to display variable values at critical points. While simple, this technique helps isolate the exact line where logic starts to deviate.

当程序行为异常时,使用打印语句在关键位置输出变量值。这种方法虽然简单,却能帮助你快速定位逻辑偏差的精确代码行。

Master your IDE’s debugger: set breakpoints by clicking next to a line number, then run the program in debug mode. Execution will pause at the breakpoint, allowing you to inspect the call stack and all variable states.

掌握 IDE 调试器:点击行号旁设置断点,然后以调试模式运行程序。执行将在断点处暂停,你可以检查调用堆栈和所有变量状态。

Use the stepping commands (Step Over, Step Into, Step Out) to move through code line by line. Watch how values change in the variables pane and compare them with expected outcomes.

使用单步执行命令 (Step Over、Step Into、Step Out) 逐行跟踪代码。在变量窗格中观察数值的变化,并与预期结果进行比对。

For logic errors that only appear under certain inputs, add conditional breakpoints that pause only when a specified expression is true, saving time when debugging large iterations.

对于仅在特定输入下出现的逻辑错误,可添加条件断点,仅当指定表达式为真时暂停,从而在大规模循环调试中节省时间。


5. Testing and Validation | 测试与验证

Write unit tests alongside your code using the unittest module in Python or JUnit in Java. Each test case should check a single function with normal, boundary and erroneous inputs.

使用 Python 的 unittest 模块或 Java 的 JUnit 为代码编写单元测试。每个测试用例应针对单一函数,涵盖正常输入、边界输入和错误输入。

For example, to test a sorting function, include tests for an empty list, a list with one element, an already sorted list, a reverse-sorted list, and a list containing duplicates.

例如,测试排序函数时,应包含空列表、单元素列表、已排序列表、逆序列表以及包含重复项的列表等测试场景。

Automate your tests so they can be run with a single command. Regularly execute the test suite after each code change to detect regressions immediately. Aim for high code coverage, especially for algorithm implementations.

将测试自动化,使其能通过一个命令全部运行。每次修改代码后,定期执行测试套件以立即发现回归问题。争取高代码覆盖率,尤其在算法实现中。


6. Data Structures in Practice | 数据结构实践

Implement a singly linked list from scratch using a Node class with data and a reference to the next node. Add methods for insertion at head/tail, deletion, and traversing while printing each element.

使用包含数据域和 next 引用的 Node 类,从零实现单链表。添加在头部/尾部插入、删除以及遍历输出每个元素的方法。

Build a stack using either a Python list or a linked list back-end. Provide push, pop, peek and is_empty operations. Test the stack by reversing a string or checking balanced parentheses.

用 Python 列表或链表作为底层结构构建栈。提供 push、pop、peek 和 is_empty 操作。通过反转字符串或检查括号匹配来测试栈。

Create a binary search tree with insert, search, and in-order traversal. Verify that the in-order output is sorted. Experiment with tree rotations or deleting nodes with two children to deepen understanding.

创建具有插入、搜索和中序遍历的二叉搜索树。验证中序遍历结果是否有序。尝试进行树旋转或删除有两个子节点的节点,以加深理解。


7. Comparing Search and Sort Algorithms | 比较搜索与排序算法

Implement linear search and binary search (requiring a sorted array). Measure the average number of comparisons for different array sizes using a counter, and plot the results.

实现线性搜索和二分搜索(需要已排序数组)。使用计数器测量不同数组规模下的平均比较次数,并绘制结果图表。

Code bubble sort, insertion sort and merge sort. Use Python’s time module to record execution times for random lists of size 100, 1000 and 10000. Present your findings in a table.

编写冒泡排序、插入排序和归并排序。使用 Python 的 time 模块记录对大小为 100、1000 和 10000 的随机列表排序的执行时间,并用表格展示结果。

Bubble sort: O(n²)    Merge sort: O(n log n)

冒泡排序:O(n²)    归并排序:O(n log n)

Analyse why the empirical timings grow as predicted by Big O notation. Comment on constant factors and caching effects that may cause small deviations.

分析为什么实际增长趋势与 Big O 表示法的预测相符,并解释可能导致微小偏差的常数因子和缓存效应。


8. Database Experiments with SQL | SQL 数据库实验

Use SQLite (built into Python via the sqlite3 module) to create a relational database. Define tables with primary keys, foreign keys and appropriate data types such as INTEGER, TEXT and REAL.

使用 SQLite(通过 Python 的 sqlite3 模块内置)创建关系数据库。定义包含主键、外键和适当数据类型 (如 INTEGER、TEXT、REAL) 的表。

Write INSERT statements to populate tables with sample data. Experiment with SELECT, DISTINCT, WHERE, ORDER BY and aggregate functions like COUNT, AVG, MAX.

编写 INSERT 语句向表中填充示例数据。练习使用 SELECT、DISTINCT、WHERE、ORDER BY 以及 COUNT、AVG、MAX 等聚合函数。

Perform JOIN operations (INNER, LEFT) to combine data from multiple tables. For example, join a Students table with Enrolments to list all students and their courses.

执行 JOIN 操作 (INNER, LEFT) 以组合多个表的数据。例如,连接 Students 和 Enrolments 表,列出所有学生及其选修课程。

Design a small scenario such as a library system or shop inventory, normalise the tables to third normal form, and implement queries that answer realistic questions.

设计一个小场景,如图书馆系统或商店库存,将表规范化到第三范式,并实现能回答实际问题的查询。


9. Network Analysis with Packet Sniffing | 网络数据包分析

Install Wireshark on a machine you own (with permission if on a school network). Start a capture on your active interface, then visit a plain HTTP website (or use a local test server).

在你自己的机器上安装 Wireshark(若在学校网络需获得许可)。启动活动接口的捕获,然后访问一个纯 HTTP 网站(或使用本地测试服务器)。

Identify the three-way TCP handshake: SYN, SYN‑ACK, ACK. Filter the capture with tcp.port == 80 and observe how sequence numbers negotiate a reliable connection.

识别 TCP 三次握手:SYN、SYN‑ACK、ACK。使用过滤器 tcp.port == 80,观察序列号如何协商建立可靠连接。

Find an HTTP GET request and its corresponding response. View the raw headers to see fields like Host, User‑Agent and Content‑Type. Compare with HTTPS traffic, noting encryption makes payload unreadable.

找到一个 HTTP GET 请求及其响应。查看原始报头中的 Host、User‑Agent 和 Content‑Type 等字段。对比 HTTPS 流量,注意加密导致负载不可读。

Capture DNS queries by filtering dns. Resolve a domain name and observe the query and response packets, noting the IP addresses and record types (A, AAAA).

使用过滤器 dns 捕获 DNS 查询。解析一个域名,观察查询和响应数据包,注意 IP 地址和记录类型 (A, AAAA)。


10. Logic Circuit Simulation | 逻辑电路仿真

Use a digital logic simulator such as Digital (by H. Neemann) or an online tool like CircuitVerse. Start by placing basic gates: AND, OR, NOT, XOR, and NAND.

使用数字逻辑仿真器,如 Digital (H. Neemann 开发) 或在线工具 CircuitVerse。从放置基本门电路开始:与门、或门、非门、异或门和与非门。

Construct a half adder using one XOR gate (for Sum) and one AND gate (for Carry). Test all input combinations (00, 01, 10, 11) and verify the truth table.

用一个异或门 (输出 Sum) 和一个与门 (输出 Carry) 构建半加器。测试所有输入组合 (00、01、10、11),验证真值表。

Build a full adder by combining two half adders and an OR gate. Then cascade four full adders to create a 4‑bit ripple carry adder. Probe the sum and carry outputs.

组合两个半加器和一个或门构建全加器。然后级联四个全加器构成四位行波进位加法器,探测和值与进位输出。

Design a simple 2‑bit multiplexer using AND, OR and NOT gates. Simulate its behaviour and understand how the select line routes data inputs to the output.

使用与门、或门和非门设计一个简单的两位多路选择器。仿真其行为,理解选择线如何将数据输入路由到输出。


11. Documenting Your Work | 实验文档化与版本控制

Keep a lab notebook or digital log that records the aim, method, results and conclusions for each experiment. Screenshots of outputs, circuit diagrams and code snippets help clarify your process.

为每个实验维护实验记录本或数字日志,记载目的、方法、结果和结论。输出截图、电路图和代码片段有助于阐明实验过程。

Initialise a Git repository in your project folder (git init). Commit your work frequently with descriptive messages such as ‘Implemented linked list insertion’.

在项目文件夹中初始化 Git 仓库 (git init)。经常提交你的工作,并使用描述性提交信息,例如 “Implemented linked list insertion”。

Push your local repository to a remote service like GitHub or GitLab. This provides a backup and demonstrates version control proficiency, which is valued in coursework and future development.

将本地仓库推送到 GitHub 或 GitLab 等远程服务。这既能提供备份,也能展示你熟练使用版本控制的能力,这在课程作业和未来开发中都备受重视。


Published by TutorHao | Computer Science Revision Series | aleveler.com

更多咨询请联系16621398022(同微信)

Comments

屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from aleveler.com

Subscribe now to keep reading and get access to the full archive.

Continue reading