Full Marks

A-level Computer Science Year 12 · Topic 1

Programming and data structures

Programming and data structures at A-level builds the skills to write well-structured, reliable programs.

We will review programming fundamentals and data structures, subroutines, parameter passing and scope.

Then we use recursion, strings, files and exceptions, and the object-oriented ideas of classes, inheritance, encapsulation and polymorphism.

In this topic

  1. 1.1Programming fundamentalsFree below · 28 questions
  2. 1.2Data structuresOpen in Full Marks · 24 questions
  3. 1.3Subroutines, structured programming, parameter passing and scopeOpen in Full Marks · 31 questions
  4. 1.4RecursionOpen in Full Marks · 24 questions
  5. 1.5String handling, file handling, random numbers and exception handlingOpen in Full Marks · 32 questions
  6. 1.6Object-oriented programming: classes, objects, inheritance, encapsulation and polymorphismOpen in Full Marks · 34 questions

1.1 · Free notes

Programming fundamentals

Diagram: Programming fundamentals

Key points

In more detail

Practice

Programming fundamentals: 10 questions

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

1. What is required for recursion to terminate?

  1. A global variable
  2. A base case
  3. An infinite loop
  4. A compiler
Show answer

B: A base case. Without a base case, the stack eventually overflows.

2. What is encapsulation in OOP?

  1. Using many classes
  2. Bundling data and methods together and hiding internal state
  3. Copying objects
  4. Inheriting from two classes
Show answer

B: Bundling data and methods together and hiding internal state. Attributes are accessed through methods rather than directly.

3. What happens when a parameter is passed by reference?

  1. A copy is made
  2. The original variable can be changed by the subroutine
  3. The program crashes
  4. It becomes a constant
Show answer

B: The original variable can be changed by the subroutine. Passing by value copies the data instead.

4. What is the scope of a local variable?

  1. The whole program
  2. Only the subroutine where it is declared
  3. All subroutines
  4. Only global code
Show answer

B: Only the subroutine where it is declared. This helps avoid unintended side effects.

5. What does polymorphism allow?

  1. Only one class in a program
  2. Objects of different classes to be treated through a common interface
  3. Faster compilation
  4. Direct access to private data
Show answer

B: Objects of different classes to be treated through a common interface. Methods can behave differently depending on the object.

6. What is a global variable?

  1. A variable used in one subroutine only
  2. A variable accessible throughout the entire program
  3. A constant
  4. A parameter
Show answer

B: A variable accessible throughout the entire program. Overuse can cause unintended side effects.

7. What is inheritance in OOP?

  1. Copying code manually
  2. A class acquiring the attributes and methods of a parent class
  3. Hiding data
  4. Passing parameters
Show answer

B: A class acquiring the attributes and methods of a parent class. It supports reuse and hierarchy.

8. Why is input validation important?

  1. It speeds up code
  2. It prevents invalid or malicious data causing errors or security issues
  3. It reduces file size
  4. It removes comments
Show answer

B: It prevents invalid or malicious data causing errors or security issues. Defensive design anticipates misuse.

9. A recursive function fact(n) returns n * fact(n-1) and has no base case. What will most likely happen when fact(3) is called?

  1. It loops without using any memory
  2. It returns 0
  3. A stack overflow error occurs
  4. It returns 6
Show answer

C: A stack overflow error occurs. With no base case the calls never stop. Each call adds a stack frame, so the call stack eventually runs out of space. It does not return 6, because that needs a base case.

10. function f(n): if n == 0 return 0, else return n + f(n-1). What value does f(4) return?

  1. 24
  2. 4
  3. 10
  4. 6
Show answer

C: 10. f(4) = 4 + 3 + 2 + 1 + f(0) = 10. It is a running sum, not a product, so 24 is wrong.

Keep going in Full Marks

Full Marks has 28 questions on Programming fundamentals (18 more than here), set out in practice levels. You also get notes and 3D models for all 6 subtopics of Programming and data structures, plus games, timed exams and past papers.

On your exam board

All A-level Computer Science Year 12 topics