J277 (9-1) Paper 2 Revision

Computational thinking, algorithms and programming. One attempt per question!

Lesson 1: Languages, Errors & Logic

High-Level vs. Low-Level

  • High-Level Languages: Use English-like words (e.g., Python, C#). They can be used on different computer hardware. They *must* be translated (compiled or interpreted).
  • Low-Level Languages: (e.g., Assembly Language). They are specific to hardware and allow direct memory manipulation.

Errors & Algorithms

  • Syntax Error: The grammar of the program is wrong (e.g., `prnit("Hello")`). The translator will find this.
  • Logic Error: The program runs, but does something unexpected (e.g., `total = num1 - num2` instead of adding).
  • Arithmetic Operators: Know the pseudocode operators: `^` (power), `MOD` (modulus, finds remainder), `+`, `-`, `*`, `/`.

Topic 1 Quiz: Languages, Errors & Logic (6 Q's)

1. "The same language can be used on computers that use different hardware." Is this High-Level or Low-Level?
2. "It allows the user to directly manipulate memory." Is this High-Level or Low-Level?
3. Which arithmetic operator is used to find the remainder of a division?
4. Which arithmetic operator is used to calculate "12 to the power of 2"?
5. A program runs, but the final score is incorrect. What type of error is this?
6. A program fails to run and the translator highlights `prnit("Hello")`. What type of error is this?

Lesson 2: Sorting Algorithms & Logic

Sorting Algorithms

  • Bubble Sort: Compares adjacent pairs of items (e.g., index 0 & 1, then 1 & 2) and swaps them if they are in the wrong order. It makes multiple passes through the list.
  • Insertion Sort: Builds a sorted list at the start of the array. It takes one item at a time from the unsorted list and inserts it into the correct position in the sorted list.
  • Similarities: Both can sort in ascending/descending order, and both are used to sort data in an array.
  • `temp` variable: In both sorts, a `temp` variable is essential for swapping two values. It holds one value temporarily while the swap occurs.

Logic Gates

  • AND gate: Output is 1 only if Input A AND Input B are both 1.
  • OR gate: Output is 1 if Input A OR Input B (or both) are 1.
  • NOT gate: Inverts the input. 1 becomes 0, 0 becomes 1.

Topic 2 Quiz: Sorting & Logic (6 Q's)

7. What is the purpose of the `temp` variable in a sorting algorithm?
8. Which sort compares adjacent pairs of items and swaps them?
9. Which sort takes an item and places it into its correct position in an already sorted part of the list?
10. Which logic gate's truth table is this? (Output is 1 only if A=1 and B=1)
11. Which logic gate's truth table is this? (Output is 1 if A=1 or B=1 or both=1)
12. A floodlight (Q) turns on if motion is detected (A) AND it is nighttime (NOT B) AND a switch is on (C). What is the logic expression?

Lesson 3: Testing & Validation

Testing

  • Why Test? To find and remove errors (bugs) and ensure the software meets the user's requirements.
  • Test Data:
    • Normal Data: Sensible data that should be accepted (e.g., `5` in a 1-10 range).
    • Erroneous Data: Data that should be rejected (e.g., `hello` or `11` in a 1-10 range).
    • Boundary Data: Data at the limits of what is acceptable (e.g., `1` and `10` in a 1-10 range).

IDE Features & Validation

  • IDE (Integrated Development Environment): Software to help programmers.
  • Breakpoints: A tool that stops the program at a specific line so the programmer can check variable values.
  • Stepping: A tool that lets the programmer run the code one line at a time.
  • Validation: Checks to ensure data entered by a user is sensible and allowed (e.g., range check for a number, presence check to ensure it's not empty).

Topic 3 Quiz: Testing & Validation (6 Q's)

13. Why is it important to test programs?
14. For a game that needs a number between 1 and 10, what would `1` and `10` be?
15. For a game that needs a number between 1 and 10, what would `hello` be?
16. Which IDE feature stops the program at a specific line so you can check variables?
17. What type of validation checks that a user has entered a number between 1 and 10?
18. What type of validation checks that a user has not left a password field blank?

Lesson 4: Data Types & Constructs

Data Types

  • Integer: Stores whole numbers (e.g., `100`).
  • Real: Stores numbers with decimal points (e.g., `10.5`).
  • Boolean: Stores only `True` or `False`.
  • String: Stores text, numbers, and symbols (e.g., `"Admin123"` or `"+44999"`).
  • Char: Stores a single character (e.g., `'A'`).

Programming Constructs

  • Sequence: Code running in order, one line after another.
  • Selection: Using `IF...THEN...ELSE` to make a decision.
  • Iteration: Using a loop (`FOR` or `WHILE`) to repeat code.
  • Concatenation: Joining two strings together, often with `+`. (e.g., `sensorType + sensorNumber`).
  • Casting: Converting a variable from one data type to another (e.g., `str(myInteger)` converts an integer to a string).

Topic 4 Quiz: Data Types & Constructs (6 Q's)

19. What is the most appropriate data type for `DoorSensorActive` (which stores `True` or `False`)?
20. What is the most appropriate data type for `EmergencyPhoneNumber` (which stores `"+449999"`)?
21. The pseudocode `sensorID = sensorType + sensorNumber` is an example of...?
22. The pseudocode `if (CheckSensorCode(sensorType)) then...` is an example of...?
23. The function `CheckSensorCode()` returns `True` or `False`. What is the data type of this returned value?
24. The program `total = total + 1` is part of a loop. This loop is an example of...?

Lesson 5: SQL & 2D Arrays

SQL (Structured Query Language)

SQL is used to manage and query data in a database.

  • SELECT: Chooses which fields (columns) to display (e.g., `SELECT SensorID`).
  • FROM: Chooses which table to get the data from (e.g., `FROM events`).
  • WHERE: Filters the records (rows) based on a condition (e.g., `WHERE SensorType = "Door"`).
  • AND: Used in a `WHERE` clause to add a second condition (e.g., `WHERE SensorType = "Door" AND Length > 20`).

2D Arrays & File Handling

  • 2D Array: An array of arrays, like a table (e.g., `arrayEvents[1, 3]`). The first number is the row, the second is the column.
  • File Handling: To save data, you must `open` a file, `write` to it, and then `close` it.
  • Casting: When saving data to an array or file, you often need to convert data types. Converting an integer to a string (e.g., `str(Length)`) is called casting.

Topic 5 Quiz: SQL & 2D Arrays (6 Q's)

25. Which SQL clause chooses which table to get data from?
26. Which SQL clause chooses which fields (columns) to display?
27. Which SQL clause filters the records (rows) based on a condition?
28. Which keyword combines two conditions in a `WHERE` clause (e.g., `SensorType = "Door"` ... `Length > 20`)?
29. The process of converting an integer variable `Length` into `"38"` to store it in a string array is called...?
30. A 2D array is stored as `arrayEvents[row, col]`. Which index would get the `SensorType` ("Window") from the first row?

Revision Complete!

Well done, Student!

You've completed the Paper 2 interactive revision.

Your final score:
0 / 0

Your Personal Feedback: