/* Computing Stage 8: six units */
(() => {
const { mc, inp, ord, DONE } = window.QH;
const C = 'computing';
BOOK.push(
{ id: 'c1', subj: C, n: '8.1', title: 'Building networks: Network structure and security', strand: 'Networks', codes: ['8NC.01', '8NC.02', '8NC.04', '8NC.05'],
  secs: [
    { n: '1.1', t: 'How devices communicate', w: 'packets',
      intro: 'Send a message across a network of routers. Watch it split into packets that take different routes.',
      tasks: [['Send the whole message', s => s.done], ['Break a router and send again', s => s.broken && s.done]],
      extra: [['ascii', {}, 'Data sent as binary']],
      notice: [<>Data is split into <b>packets</b>, each with a sequence number and the destination address.</>, <>Packets can take <b>different routes</b> and are reassembled at the destination.</>, <>If a route fails, packets are <b>re-routed</b>: that is packet switching.</>],
      check: [mc('Why are packets numbered?', ['To make them faster', 'So they can be put back in order', 'To encrypt them', 'For the router\'s name'], 1, 'They may arrive out of order.'), mc('What happens if one router fails?', ['All data is lost', 'Packets take another route', 'The message is sent twice', 'Nothing can be sent'], 1, 'Packet switching re-routes around the failure.')] },
    { n: '1.2', t: 'Network structure (topologies)', w: 'topology',
      intro: 'Switch between topologies. Make a device or cable fail and see what still works.',
      tasks: [['Try all four topologies', s => s.seen >= 4], ['Make the central switch fail in a star network', (s, H) => H('down', 'hub')]],
      notice: [<><b>Star</b>: every device connects to a central switch. Reliable and easy to scale, but the switch is a single point of failure.</>, <><b>Mesh</b>: many routes, so it is very reliable but needs lots of cabling.</>, <><b>Bus</b> and <b>ring</b> are cheap, but one break can stop everything.</>],
      check: [mc('Which topology is easiest to expand?', ['Bus', 'Ring', 'Star', 'None'], 2, 'Just add a cable to the switch.'), mc('The internet is best described as…', ['a bus', 'a ring', 'a (partial) mesh', 'a single star'], 2, 'Many routes between routers.')] },
    { n: '1.3', t: 'Network hardware & scalability', w: 'labeldiag', cfg: { d: 'nethw' },
      intro: 'Explore the hardware in a school network, then label it from memory.',
      tasks: [['Explore every device', s => s.explored >= s.total], ['Label every device', s => s.labelled >= s.total]],
      extra: [['match', { h: ['Device', 'Job'], pairs: [['Router', 'Connects different networks'], ['Switch', 'Connects devices on a LAN'], ['NIC', 'Lets a device join a network'], ['WAP', 'Provides Wi-Fi'], ['Server', 'Provides services to clients']] }, 'Match device to job']],
      notice: [<>A <b>switch</b> connects devices on a LAN; a <b>router</b> connects networks together.</>, <>Every device needs a <b>NIC</b>; a <b>WAP</b> adds wireless devices.</>, <>A <b>scalable</b> network can grow by adding switches and access points.</>],
      check: [mc('Which device connects a home network to the internet?', ['Switch', 'Router', 'NIC', 'Monitor'], 1, 'It routes between networks.'), mc('What does "scalable" mean?', ['It is very fast', 'It can easily grow to more users or devices', 'It is wireless', 'It is secure'], 1, 'It can be expanded.')] },
    { n: '1.4', t: 'Threats and protection', w: 'match',
      cfg: { h: ['Threat', 'Protection'], pairs: [['Malware (virus, worm)', 'Anti-malware software, updates'], ['Hacking (unauthorised access)', 'Firewall, strong passwords'], ['Phishing emails', 'User training, check the sender'], ['Data intercepted on Wi-Fi', 'Encryption (WPA2/WPA3)'], ['Weak passwords', 'Two-factor authentication'], ['Denial of service (DoS)', 'Firewall, traffic monitoring']] },
      intro: 'Match each network threat to the best way engineers protect against it.',
      tasks: DONE,
      extra: [['sort', { bins: ['Strong password', 'Weak password'], items: [['password123', 1], ['Tr0ub4dor&3!', 0], ['qwerty', 1], ['My-Cat-Eats-7-Fish!', 0], ['your name + birthday', 1], ['correct-horse-battery-staple', 0]] }, 'Strong or weak password?']],
      notice: [<><b>Malware</b> is malicious software; keep anti-malware updated.</>, <>A <b>firewall</b> blocks unauthorised traffic; <b>encryption</b> scrambles data so it can't be read if intercepted.</>, <>People are often the weakest link: <b>phishing</b> tricks users, so training matters.</>],
      check: [mc('What does encryption do?', ['Deletes viruses', 'Scrambles data so only the intended receiver can read it', 'Speeds up the network', 'Blocks all websites'], 1, 'Data needs a key to decode.'), mc('An email asks you to "confirm your password" via a link. This is…', ['spam only', 'phishing', 'a firewall', 'encryption'], 1, 'It tries to trick you.')] },
  ],
  practice: [mc('Which is a single point of failure in a star network?', ['Any device', 'The central switch', 'A cable', 'The printer'], 1, 'If it fails, everything stops.'), mc('A NIC is needed to…', ['store files', 'connect a device to a network', 'print', 'encrypt'], 1, 'Network interface card.'), mc('Two-factor authentication means…', ['two passwords', 'a password plus a second proof, e.g. a code on your phone', 'two users', 'two firewalls'], 1, 'Something you know + something you have.')],
  challenge: [mc('A school wants a network that keeps working even if one cable breaks. Which topology, and why?', ['Bus: it\'s cheap', 'Mesh: there are alternative routes', 'Ring: data goes one way', 'Star: no cables'], 1, 'Redundant links.'), mc('Why is data split into packets rather than sent as one block?', ['To look professional', 'Packets can share network links, take the best routes, and only lost packets are resent', 'It uses less electricity', 'Packets are encrypted automatically'], 1, 'Efficient and resilient.')],
  recap: { points: ['Packets: numbered, routed separately, reassembled.', 'Topologies: star (scalable), mesh (resilient), bus/ring (cheap but fragile).', 'Hardware: router, switch, NIC, WAP, server.', 'Security: firewall, encryption, anti-malware, strong passwords, 2FA, user training.'], terms: [['Packet', 'A small chunk of data with a header.'], ['Firewall', 'Filters network traffic using rules.'], ['Encryption', 'Scrambling data so it needs a key to read.']] } },

{ id: 'c2', subj: C, n: '8.2', title: "It's all in the planning: Pseudocode and algorithms", strand: 'Computational thinking', codes: ['8CT.01', '8CT.02', '8P.02'],
  secs: [
    { n: '2.1', t: 'Pseudocode and flowcharts', w: 'pseudoflow',
      intro: 'Step through the algorithm with different inputs. Watch the pseudocode and the flowchart highlight together.',
      tasks: [['Trace an even number to the end', s => s.done && s.n % 2 === 0], ['Trace an odd number to the end', s => s.done && s.n % 2 === 1]],
      extra: [['match', { h: ['Flowchart symbol', 'Meaning'], pairs: [['Oval', 'Start / stop'], ['Parallelogram', 'Input / output'], ['Rectangle', 'Process'], ['Diamond', 'Decision']] }, 'Flowchart symbols']],
      notice: [<><b>Pseudocode</b> is structured English for planning code; it ignores exact syntax.</>, <>A <b>flowchart</b> shows the same algorithm as connected symbols.</>, <>A diamond is a <b>decision</b>: the flow takes one of two paths (selection).</>],
      check: [mc('Which symbol is used for a decision?', ['Oval', 'Rectangle', 'Diamond', 'Parallelogram'], 2, 'Yes/no branches.'), mc('Why plan with pseudocode first?', ['It runs faster', 'To focus on the logic before worrying about syntax', 'It\'s required by Python', 'It is shorter'], 1, 'Plan the logic first.')] },
    { n: '2.2', t: 'Sending text and numbers with ASCII', w: 'ascii',
      intro: 'Type a message and send it from one micro:bit to the other. See each character as an ASCII code in binary.',
      tasks: [['Send a message', s => s.sent > 0], ['Send a message with at least 5 characters', s => s.sent > 0 && s.len >= 5]],
      notice: [<>Every character has an <b>ASCII code</b>: A = 65, B = 66 … a = 97.</>, <>The code is stored and transmitted as <b>binary</b>.</>, <>micro:bits on the same <b>radio group</b> can exchange messages.</>],
      check: [inp("'A' is 65 in ASCII. What is 'C'?", '67', 'Letters are consecutive: A 65, B 66, C 67.'), mc('Why must both micro:bits use the same radio group?', ['To save battery', 'So they only listen to each other\'s messages', 'For speed', 'To encrypt'], 1, 'Like a channel.')] },
    { n: '2.3', t: 'Sending an image', w: 'ledgrid',
      intro: 'Design a 5 × 5 image. See how it becomes a string that can be sent by radio.',
      tasks: [['Light at least 8 LEDs', s => s.on >= 8]],
      notice: [<>An image is <b>data</b> too: each LED is a number from 0 (off) to 9 (bright).</>, <>The rows are joined with ":" to make a <b>string</b> that can be sent.</>, <>The receiver rebuilds the image from the string.</>],
      check: [mc('How many values describe a 5 × 5 micro:bit image?', ['5', '10', '25', '50'], 2, '5 × 5.'), mc('"00000" as a row means…', ['all LEDs bright', 'all LEDs off', 'error', 'five images'], 1, '0 = off.')] },
  ],
  practice: [mc('What does an algorithm describe?', ['The hardware', 'A precise sequence of steps to solve a problem', 'A virus', 'A file type'], 1, 'Steps.'), inp("ASCII for 'a' is 97. What is 'd'?", '100', '97, 98, 99, 100.'), mc('In pseudocode, OUTPUT means…', ['read a value', 'display a value', 'repeat', 'decide'], 1, 'Show it.')],
  challenge: [mc('An algorithm must output "pass" if the mark is ≥ 50, otherwise "fail". Which construct?', ['Sequence only', 'Selection (IF … ELSE)', 'Iteration only', 'Variables only'], 1, 'Choose between two paths.'), mc('The micro:bit receives "HELO". What is the most likely cause?', ['Wrong radio group', 'The sender\'s algorithm or typing had an error', 'ASCII changed', 'The battery'], 1, 'The data is sent exactly as written.')],
  recap: { points: ['Plan with pseudocode or flowcharts before coding.', 'Characters are sent as ASCII codes in binary.', 'Images can be encoded as strings of numbers.'], terms: [['Pseudocode', 'Code-like English for planning.'], ['ASCII', 'A code giving each character a number.'], ['Algorithm', 'A precise set of steps.']] } },

{ id: 'c3', subj: C, n: '8.3', title: "Let's talk technology: What's going on inside", strand: 'Computer systems', codes: ['8CS.01', '8CS.02', '8CS.03', '8CS.04'],
  secs: [
    { n: '3.1', t: 'Types of software', w: 'sort',
      cfg: { bins: ['System software', 'Application software'], items: [['Operating system (Windows)', 0], ['Word processor', 1], ['Anti-malware utility', 0], ['Web browser', 1], ['Device driver', 0], ['Photo editor', 1], ['File compression utility', 0], ['Game', 1]] },
      intro: 'Sort the software into system software (runs the computer) and application software (does tasks for the user).',
      tasks: DONE,
      notice: [<><b>System software</b> manages the hardware: the operating system, drivers and utilities.</>, <><b>Application software</b> lets users do tasks: writing, browsing, editing.</>, <>The OS provides the <b>user interface</b> and manages memory, files and devices.</>],
      check: [mc('A device driver is…', ['application software', 'system software', 'hardware', 'a virus'], 1, 'It lets the OS control the hardware.'), mc('Which job does the operating system do?', ['Edit photos', 'Manage memory and files', 'Write essays', 'Play music'], 1, 'It manages resources.')] },
    { n: '3.2', t: 'Computer memory', w: 'labeldiag', cfg: { d: 'memory' },
      intro: 'Explore the different types of memory and storage, then label them.',
      tasks: [['Explore every part', s => s.explored >= s.total], ['Label them all', s => s.labelled >= s.total]],
      extra: [['order', { rounds: [{ p: 'Order from fastest to slowest', items: ['Registers', 'Cache', 'RAM', 'SSD', 'Hard disk drive'] }] }, 'Speed hierarchy'], ['sort', { bins: ['Volatile', 'Non-volatile'], items: [['RAM', 0], ['Cache', 0], ['ROM', 1], ['SSD', 1], ['USB stick', 1], ['Registers', 0]] }, 'Volatile or not?']],
      notice: [<><b>RAM</b> is volatile: it is lost when the power is off. <b>ROM</b> is non-volatile and holds start-up instructions.</>, <><b>Cache</b> is small but very fast and stores frequently used data near the CPU.</>, <><b>Secondary storage</b> (SSD/HDD) keeps files permanently.</>],
      check: [mc('What happens to RAM when you switch off?', ['It is saved', 'Its contents are lost', 'It moves to cache', 'Nothing'], 1, 'Volatile.'), mc('Why does more cache make a CPU faster?', ['It is bigger than RAM', 'Frequently used data is closer and quicker to reach', 'It cools the CPU', 'It stores files'], 1, 'Less waiting.')] },
    { n: '3.3', t: 'Binary and denary', w: 'binary',
      intro: 'Toggle bits to make each target number. Watch the place values add up.',
      tasks: DONE,
      notice: [<>Binary is base 2: the place values are <b>128, 64, 32, 16, 8, 4, 2, 1</b>.</>, <>To convert binary → denary, <b>add the place values</b> of the 1s.</>, <>8 bits = 1 byte, which stores <b>0 to 255</b>.</>],
      check: [inp('Convert 00001010 to denary.', '10', '8 + 2.'), inp('Convert 37 to 8-bit binary.', '00100101', '32 + 4 + 1.')] },
    { n: '3.4', t: 'File compression', w: 'compress',
      intro: 'Draw on the 8 × 8 image and watch the run-length encoding change. Which images compress best?',
      tasks: [['Make an image that compresses to fewer than 30 values', s => s.size < 30]],
      notice: [<><b>Compression</b> reduces file size, so files are faster to send and take less storage.</>, <><b>Lossless</b> (e.g. RLE, ZIP) can be perfectly restored; <b>lossy</b> (JPEG, MP3) removes some detail.</>, <>Images with large areas of the same colour compress well with RLE.</>],
      check: [mc('Which is lossy?', ['ZIP', 'Run-length encoding', 'JPEG', 'PNG'], 2, 'JPEG removes detail.'), mc('Why compress a video before emailing it?', ['To improve quality', 'To make the file smaller so it sends faster', 'To encrypt it', 'To add sound'], 1, 'Smaller file.')] },
    { n: '3.5', t: 'Logic gates and truth tables', w: 'logic',
      intro: 'Toggle the inputs of each gate and compare with its truth table.',
      tasks: [['Try AND, OR and NOT', s => s.seen >= 3], ['Make an AND gate output 1', (s, H) => H('Q', 1)]],
      notice: [<><b>AND</b>: output 1 only if both inputs are 1.</>, <><b>OR</b>: output 1 if either input is 1. <b>NOT</b>: reverses the input.</>, <>A <b>truth table</b> lists the output for every combination of inputs.</>],
      check: [mc('AND gate, A = 1, B = 0. Output?', ['0', '1'], 0, 'Both must be 1.'), mc('OR gate, A = 0, B = 1. Output?', ['0', '1'], 1, 'Either is enough.')] },
    { n: '3.6', t: 'Robotics, AI and augmented reality', w: 'labeldiag', cfg: { d: 'aitech' },
      intro: 'Explore how robots, artificial intelligence and augmented reality work, then label the diagram.',
      tasks: [['Explore each part', s => s.explored >= s.total]],
      extra: [['sort', { bins: ['Robotics', 'Artificial intelligence', 'Augmented reality'], items: [['Factory welding arm', 0], ['Voice assistant', 1], ['Furniture-placing phone app', 2], ['Self-driving car decisions', 1], ['Mars rover wheels and arm', 0], ['Face filter on camera', 2]] }, 'Classify the technology']],
      notice: [<><b>Robots</b> use sensors (input), a processor and actuators (output).</>, <><b>AI</b> learns from data to make predictions or decisions.</>, <><b>AR</b> overlays computer images on the real world through a camera.</>],
      check: [mc('Which is an actuator?', ['Camera', 'Motor', 'Microphone', 'Light sensor'], 1, 'It causes movement.'), mc('AR differs from VR because AR…', ['blocks out the real world', 'adds digital content to the real world', 'needs no screen', 'is only for games'], 1, 'Augmented reality overlays content.')] },
  ],
  practice: [inp('Binary 11111111 in denary?', '255', 'The maximum value of a byte.'), mc('Which memory holds the boot instructions?', ['RAM', 'ROM', 'Cache', 'Registers'], 1, 'ROM.'), mc('NOT 1 = ?', ['0', '1'], 0, 'Reversed.')],
  challenge: [mc('A gate outputs 1 only when both sensors detect a person. Which gate?', ['OR', 'AND', 'NOT', 'None'], 1, 'Both inputs must be 1.'), inp('How many different values can 4 bits represent?', '16', '2⁴ = 16.')],
  recap: { points: ['System vs application software.', 'Registers > cache > RAM > secondary storage (speed); RAM is volatile.', 'Binary place values 128…1; 8 bits = 1 byte.', 'Compression: lossless vs lossy. Logic gates: AND, OR, NOT.'], terms: [['Volatile', 'Loses its data without power.'], ['Byte', '8 bits.'], ['Truth table', 'Shows the outputs for all inputs.']] } },

{ id: 'c4', subj: C, n: '8.4', title: 'Testing conditions: Developing games', strand: 'Programming', codes: ['8P.01', '8P.03', '8CT.03'],
  secs: [
    { n: '4.1', t: 'Decomposing a game', w: 'labeldiag', cfg: { d: 'decomp' },
      intro: 'Explore how a big game project is broken down into smaller sub-problems.',
      tasks: [['Explore every part', s => s.explored >= s.total]],
      extra: [['sort', { bins: ['Input', 'Process', 'Output'], items: [['Player presses a key', 0], ['Check if the answer is correct', 1], ['Show "Well done!"', 2], ['Add 1 to the score', 1], ['Player types a name', 0], ['Display the high score', 2]] }, 'Input, process or output?']],
      notice: [<><b>Decomposition</b> breaks a complex problem into smaller parts.</>, <>Each part can be planned, coded and tested on its own.</>, <>Look for <b>patterns</b>: parts that repeat can share code.</>],
      check: [mc('Decomposition means…', ['deleting code', 'breaking a problem into smaller parts', 'testing', 'compressing'], 1, 'Break it down.'), mc('Why decompose before coding?', ['It\'s optional', 'Smaller parts are easier to solve and test', 'Python needs it', 'To use less memory'], 1, 'Manageable chunks.')] },
    { n: '4.2', t: 'Selection: if, elif, else', w: 'pygame',
      intro: 'Play the guessing game. Watch which branch of the Python code runs for each guess.',
      tasks: [['Make the "Too low" branch run', (s, H) => H('tries', 1)], ['Win the game', s => s.won]],
      notice: [<><b>Selection</b> chooses between paths using conditions.</>, <><b>if / elif / else</b>: only the first true branch runs.</>, <>Comparison operators: <b>==, !=, &lt;, &gt;, &lt;=, &gt;=</b>.</>],
      check: [mc('Which operator checks equality in Python?', ['=', '==', '!=', '=>'], 1, '= assigns, == compares.'), mc('If guess = 9 and secret = 7, which branch runs?', ['if guess == secret', 'elif guess < secret', 'else', 'none'], 2, '9 is greater than 7.')] },
    { n: '4.3', t: 'Sequencing the code', w: 'order',
      cfg: { rounds: [{ p: 'Put the game code in the right sequence', items: ['score = 0', 'answer = input("2 + 3 = ? ")', 'if answer == "5":', '    score = score + 1', 'print("Score:", score)'] }] },
      intro: 'Put the lines of Python in the right order. Sequence matters!',
      tasks: DONE,
      notice: [<><b>Sequence</b>: instructions run in order, top to bottom.</>, <>Variables must be <b>set before</b> they are used.</>, <>Indentation shows which lines belong <b>inside</b> an if.</>],
      check: [mc('What happens if you print score before setting it?', ['It prints 0', 'An error: score is not defined', 'It prints nothing', 'It works'], 1, 'The variable doesn\'t exist yet.'), mc('In Python, indentation…', ['is decoration', 'shows which code is inside a block', 'is an error', 'is optional'], 1, 'It defines blocks.')] },
  ],
  practice: [mc('Which keyword checks a second condition?', ['else', 'elif', 'then', 'while'], 1, 'Else-if.'), mc('x = 5. Which is True?', ['x > 5', 'x != 5', 'x >= 5', 'x < 5'], 2, '5 ≥ 5.'), mc('A brief is…', ['the final code', 'a description of what the client wants', 'a bug', 'a variable'], 1, 'The requirements.')],
  challenge: [mc('Code: if mark >= 70: print("A") / elif mark >= 50: print("B") / else: print("C"). Output for 70?', ['A', 'B', 'C', 'A and B'], 0, 'The first true branch runs, and 70 ≥ 70.'), mc('A game must give 3 lives and end at 0. What do you need?', ['Only selection', 'A variable for lives, plus selection to check when it is 0', 'Only input', 'A logic gate'], 1, 'Variable + condition.')],
  recap: { points: ['Decompose complex problems.', 'Sequence: order matters. Selection: if / elif / else.', 'Comparison operators produce True / False.'], terms: [['Selection', 'Choosing a path based on a condition.'], ['Condition', 'An expression that is True or False.'], ['Decomposition', 'Breaking a problem into smaller parts.']] } },

{ id: 'c5', subj: C, n: '8.5', title: 'Data input: Data collection and validation', strand: 'Managing data', codes: ['8MD.01', '8MD.02', '8MD.03'],
  secs: [
    { n: '5.1', t: 'Validation checks', w: 'validate',
      intro: 'Fix each input so it passes its validation check.',
      tasks: [['Make every field accepted', s => s.all]],
      extra: [['testtable', {}, 'Test with normal, boundary and erroneous data']],
      notice: [<><b>Validation</b> automatically checks that data is sensible: range, presence, length, format, type and lookup checks.</>, <>Validation <b>cannot</b> tell if data is correct, only that it is reasonable.</>, <><b>Verification</b> checks the data was entered accurately, e.g. double entry.</>],
      check: [mc('Age must be 11–16. Which check?', ['Presence', 'Range', 'Length', 'Lookup'], 1, 'Between limits.'), mc('Typing an email twice to confirm it is…', ['validation', 'verification', 'a range check', 'a lookup'], 1, 'Double entry.')] },
    { n: '5.2', t: 'Designing data-capture forms', w: 'labeldiag', cfg: { d: 'formdes' },
      intro: 'Explore the features of a good data-capture form, then label them.',
      tasks: [['Explore every feature', s => s.explored >= s.total], ['Label them all', s => s.labelled >= s.total]],
      notice: [<>Good forms are <b>clear</b> and use the right controls (drop-downs, radio buttons).</>, <>Restricting choices <b>reduces errors</b>.</>, <>Validation on the form catches mistakes <b>before</b> they are stored.</>],
      check: [mc('Best control for choosing one of three year groups?', ['Free text box', 'Drop-down list or radio buttons', 'Password field', 'Image'], 1, 'Limited valid options.'), mc('Why show "DD/MM/YYYY" on a date field?', ['Decoration', 'It tells users the format, so fewer errors', 'It encrypts', 'It is required'], 1, 'Guidance.')] },
    { n: '5.3', t: 'Spreadsheet models and what-if', w: 'whatif',
      intro: 'Change the inputs in the cake sale model. Which price makes the most profit?',
      tasks: [['Make a profit of at least $150', s => s.profit >= 150], ['Find a situation that makes a loss', s => s.profit < 0]],
      notice: [<><b>Formulae</b> link cells: =B1*B2.</>, <>Changing an input <b>automatically updates</b> the results.</>, <><b>What-if</b> questions test predictions before committing.</>],
      check: [mc('Formula for income if price is in B1 and number sold in B2?', ['=B1+B2', '=B1*B2', '=B1/B2', 'B1B2'], 1, 'Price × quantity.'), mc('A what-if question is useful because…', ['it deletes data', 'you can test options without real risk', 'it validates', 'it makes charts'], 1, 'A model predicts outcomes.')] },
  ],
  practice: [mc('Phone number must be 11 digits. Which check?', ['Range', 'Length', 'Presence', 'Type'], 1, 'Number of characters.'), mc('A required field uses a…', ['presence check', 'range check', 'format check', 'lookup'], 0, 'Not blank.'), mc('Which spreadsheet formula adds A1 to A5?', ['=SUM(A1:A5)', '=ADD(A1-A5)', 'SUM A1 A5', '=A1:A5'], 0, 'SUM over a range.')],
  challenge: [mc('A date of birth "31/02/2012" passes a format check. Why is it still a problem?', ['It is the wrong format', 'Format checks only test the pattern; the 31st of February doesn\'t exist', 'It is too long', 'It is fine'], 1, 'Validation has limits.'), mc('Boundary test data for "accept 1–100" would be…', ['50', '1 and 100 (and 0, 101)', '"abc"', '-50'], 1, 'At the edges.')],
  recap: { points: ['Validation: range, presence, length, format, type, lookup.', 'Verification: double entry and visual checks.', 'Forms: suitable controls reduce errors.', 'Spreadsheet formulae enable what-if modelling.'], terms: [['Validation', 'An automatic check that data is sensible.'], ['Verification', 'A check that data was entered accurately.'], ['Model', 'A spreadsheet that represents a real situation.']] } },

{ id: 'c6', subj: C, n: '8.6', title: 'Iterating through a solution: Software design and development', strand: 'Programming', codes: ['8P.04', '8P.02', '8CT.05'],
  secs: [
    { n: '6.1', t: 'The development cycle', w: 'labeldiag', cfg: { d: 'devcycle' },
      intro: 'Explore each stage of iterative development, then label the cycle.',
      tasks: [['Explore every stage', s => s.explored >= s.total], ['Label the cycle', s => s.labelled >= s.total]],
      notice: [<>Projects follow a cycle: <b>analyse → design → code → test → evaluate</b>.</>, <><b>Iterative</b> development repeats the cycle, improving the solution each time.</>, <>Each iteration adds features or fixes problems found in testing.</>],
      check: [mc('Which stage involves pseudocode?', ['Analyse', 'Design', 'Test', 'Evaluate'], 1, 'Planning the algorithm.'), mc('Iterative development means…', ['writing everything at once', 'repeating the cycle to improve the solution', 'never testing', 'deleting old versions'], 1, 'Repeat and improve.')] },
    { n: '6.2', t: 'Recycling quiz with selection', w: 'recycle',
      intro: 'Run the recycling quiz for different items. Follow the decisions and see the Python behind it.',
      tasks: [['Test at least 4 different items', s => s.seen >= 4]],
      notice: [<>The quiz uses <b>nested selection</b>: each answer leads to the next question.</>, <>Each path ends with one outcome.</>, <>Plan the decisions as a flowchart before coding.</>],
      check: [mc('A greasy pizza box is not "clean and dry". Where does the quiz send it?', ['Recycling', 'General waste', 'Special collection', 'Nowhere'], 1, 'The second check fails.'), mc('Why plan the quiz as a flowchart first?', ['It is quicker to draw than to think', 'To check that every path leads to a correct outcome', 'Python needs it', 'To use less memory'], 1, 'Check the logic.')] },
    { n: '6.3', t: 'Testing and improving', w: 'testtable',
      intro: 'Run each test and record the actual result. Does the program pass?',
      tasks: [['Run every test', s => s.done]],
      notice: [<>Test with <b>normal, boundary and erroneous</b> data.</>, <>Compare <b>expected vs actual</b> results in a test table.</>, <>Fix the failures, then <b>re-test</b>: that's iteration.</>],
      check: [mc('For "accept 11 to 16", 16 is…', ['normal', 'boundary', 'erroneous', 'invalid'], 1, 'At the edge.'), mc('"abc" for an age field is…', ['normal', 'boundary', 'erroneous', 'extreme'], 2, 'The wrong type.')] },
  ],
  practice: [mc('Which stage checks that the solution meets the requirements?', ['Code', 'Evaluate', 'Design', 'Analyse'], 1, 'Evaluate.'), mc('A test table records…', ['only errors', 'test data, expected and actual results', 'the code', 'the users'], 1, 'Compare them.'), mc('An item "Battery: hazardous = yes" goes to…', ['recycling', 'general waste', 'a special collection point', 'compost'], 2, 'Hazardous.')],
  challenge: [mc('After testing, the quiz sends glass to general waste by mistake. What should happen next?', ['Release it anyway', 'Find and fix the logic error, then re-test (iterate)', 'Delete the program', 'Add more questions'], 1, 'Iterate.'), mc('Why include erroneous test data?', ['To crash the program on purpose for fun', 'To check the program handles unexpected input without failing', 'It is not needed', 'To fill the table'], 1, 'Robustness.')],
  recap: { points: ['Analyse → design → code → test → evaluate, repeated.', 'Nested selection for multi-step decisions.', 'Test tables: normal, boundary, erroneous; fix and re-test.'], terms: [['Iteration (development)', 'Repeating the cycle to improve.'], ['Requirements', 'What the solution must do.'], ['Erroneous data', 'Invalid input used for testing.']] } },
);
})();
