9618/31/M/J/21 question 9: worked solution (May/June 2021, paper 31)

Show as plain text

Cambridge A2 Level Computer Science 9618 · 20.1 Programming Paradigms Worked solution from the Further Programming Paper 3 Advanced Theory booklet, Part 1 of 2. Q1 9618/31/M/J/21 original Q9 Structured · 8 marks Worked solution (a) An imperative (procedural) language tells the computer how to do a task, step by step. Write: Programs use variables whose values are changed by assignment statements [1] Write: The statements are a sequence of commands carried out in the order written , often with repetition (iteration) [1] (b) A declarative language says what result is wanted, not how to get it. Write: The programmer states what needs to be done instead of how to do it [1] Write: It uses facts and rules , and queries to satisfy a goal (it can be logical or functional) [1] (c) Look at the style of each piece of code: Program code example Programming paradigm male(john). female(ethel). parent(john, ethel). Declarative FOR Counter = 1 TO 20 ... NEXT Counter Procedural / imperative Start: LDD Counter, INC ACC, STO Counter Low-level / assembly public class Vehicle { ... } Object-oriented (OOP) Facts written as male(john). is declarative [1] A FOR loop with assignment is procedural / imperative [1] LDD, INC and STO instructions are low-level (assembly language) [1] A class with private data and a constructor is object-oriented [1] KEY IDEA Imperative code gives step-by-step commands, declarative code states facts and goals, low-level code uses processor instructions and OOP is built on classes. TOTAL 8 marks Official mark scheme VIDEO ▶ Topic lesson A lesson on this topic · by Craig'n'Dave. Tap the picture to open it on YouTube.