Full Marks

GCSE Computer Science · Topic 12

Practical programming and exam skills

Practical programming and exam skills is about writing, testing and improving real programs, and answering exam questions well.

We will turn a specification into working code, and debug and trace unfamiliar programs.

Then we implement searching and sorting algorithms, and practise evaluating solutions and writing extended answers.

In this topic

  1. 12.1Translating a specification into a working programFree below · 31 questions
  2. 12.2Debugging and tracing unfamiliar programsOpen in Full Marks · 30 questions
  3. 12.3Implementing searching and sorting algorithms in codeOpen in Full Marks · 25 questions
  4. 12.4Evaluating solutions and exam technique for code and extended-response questionsOpen in Full Marks · 17 questions

12.1 · Free notes

Translating a specification into a working program

Diagram: Translating a specification into a working program

Key points

In more detail

Practice

Translating a specification into a working program: 10 questions

Pick an answer to check it, or open the answer for the explanation.

1. A spec states: 'The program must keep asking until the age entered is between 11 and 18.' Which structure is most suitable?

  1. One IF statement that prints an error once
  2. An array holding the numbers 11 to 18
  3. A FOR loop that runs from 11 to 18
  4. A WHILE loop that repeats while the age is outside 11–18
Show answer

D: A WHILE loop that repeats while the age is outside 11–18. The number of attempts is unknown, so a condition-controlled loop (WHILE/REPEAT) is needed. It repeats the input until the range check is passed.

2. In Python, age = input('Age: ') followed by print(age + 1) gives an error. What is the best fix?

  1. Use age = int(input('Age: '))
  2. Add a colon after input
  3. Use age = str(1)
  4. Declare age as a constant
Show answer

A: Use age = int(input('Age: ')). input() returns a string, and a string cannot be added to the integer 1. Casting with int() converts the input to a number first.

3. A spec requires 30 student names to be stored and then processed in a loop. Which data structure is most suitable?

  1. A one-dimensional array of 30 strings
  2. A Boolean variable
  3. One long string with no separators
  4. 30 separate variables
Show answer

A: A one-dimensional array of 30 strings. A 1D array/list holds many items of the same type and can be accessed by index inside a loop, so it needs far less code than 30 variables.

4. A spec says valid marks are 0 to 100 inclusive. Which of these is boundary test data for the upper limit?

  1. -5
  2. 100
  3. 'ten'
  4. 50
Show answer

B: 100. Boundary data sits at the edge of the valid range. 100 is the highest valid value, and 101 would be the first invalid one. 50 is normal, 'ten' and -5 are erroneous.

5. A subprogram must calculate the area of a rectangle and send the answer back to the main program. What should it be?

  1. A procedure that only prints the area
  2. A function that uses return
  3. A constant
  4. A count-controlled loop
Show answer

B: A function that uses return. A function returns a value to the part of the program that called it. A procedure carries out actions but does not return a value.

6. Why declare VAT_RATE = 0.2 as a constant at the top instead of typing 0.2 everywhere?

  1. It removes the need for variables
  2. Constants can be changed while the program runs
  3. The value can be changed in one place and the code is easier to read
  4. It makes the program run faster
Show answer

C: The value can be changed in one place and the code is easier to read. A named constant makes the code self-documenting and, if the rate changes, only one line needs editing. It does not change speed, and constants should not change at run time.

7. A spec: tickets cost £8 each, with a 10% discount when 5 or more are bought. What total should be output for 5 tickets?

  1. £32.00
  2. £36.00
  3. £4.00
  4. £40.00
Show answer

B: £36.00. 5 × £8 = £40. Five tickets qualifies for the discount, 10% of £40 is £4, so the total is £40 − £4 = £36.00.

8. A spec says passwords must contain at least 8 characters. Which validation check does this describe?

  1. Range check
  2. Length check
  3. Type check
  4. Presence check
Show answer

B: Length check. A length check tests the number of characters entered. A presence check only tests that something has been entered.

9. A spec requires totalling exactly 5 scores entered by the user. Which loop is most suitable?

  1. A WHILE loop where the counter never changes
  2. A count-controlled FOR loop that runs 5 times
  3. An IF statement with no loop
  4. A nested loop that runs 5 × 5 times
Show answer

B: A count-controlled FOR loop that runs 5 times. The number of repeats is known in advance, so a count-controlled FOR loop is ideal. A WHILE loop with no change to its counter would never stop.

10. When should the expected results in a test plan be written?

  1. Only for tests that fail
  2. Before running the tests, worked out from the specification
  3. After running the program, copied from the output
  4. They are not needed if the program runs
Show answer

B: Before running the tests, worked out from the specification. Expected results come from the spec, not the program. Writing them first means actual output can be compared fairly and any errors show up.

Keep going in Full Marks

Full Marks has 31 questions on Translating a specification into a working program (21 more than here), set out in practice levels. You also get notes and 3D models for all 4 subtopics of Practical programming and exam skills, plus games, timed exams and past papers.

On your exam board

All GCSE Computer Science topics