TopicalComputer Science 9618Topic 20Programming ParadigmsPaper 3

Programming Paradigms — Paper 3 · A Level Computer Science 9618

20.1· 13 questions · 95 marks · 114 min · 2021–2022· Structured questions

Every Cambridge A Level Computer Science Paper 3 question on programming paradigms, laid out as 14 A4 pages with the mark scheme below. Nothing is left out. Free to read, no account.

Different topic or paper

Questions14 pages

Question 1: (a) Describe what is meant by an imperative (procedural) programming language. ............................................................…1 / 14
Question 2: (a) Describe what is meant by an imperative (procedural) programming language. ............................................................…2 / 14
Question 3: (a) Describe what is meant by an imperative (procedural) programming language. ............................................................…3 / 14
Question 4: Draw one line from each programming paradigm to its most appropriate description. Programming paradigm Description Programs using the instr…4 / 14
Question 5: Draw one line from each programming paradigm to its most appropriate description. Programming paradigm Description Programs using the instr…Question 6: A declarative language is used to represent the following facts about cats. 01 type(leopard, wild). 02 type(lion, wild). 03 type(cheetah, w…5 / 14
Question 6 (continued)Question 7: A program is to be written using Object-Oriented Programming (OOP) for a shop that sells knitting yarn. There are three types of yarn: acry…6 / 14
Question 7 (continued)7 / 14
Question 8: A declarative language is used to represent the following facts about a school. 01 teaches(alan, mathematics). 02 teaches(ioana, geography)…8 / 14
Question 8 (continued)Question 9: A declarative language is used to represent the following facts about cats. 01 type(leopard, wild). 02 type(lion, wild). 03 type(cheetah, w…9 / 14
Question 9 (continued)Question 10: A program is to be written using Object-Oriented Programming (OOP) for a shop that sells knitting yarn. There are three types of yarn: acry…10 / 14
Question 10 (continued)11 / 14
Question 11: (a) Define these Object-Oriented Programming (OOP) terms: Instance ........................................................................…12 / 14
Question 12: (a) Define these Object-Oriented Programming (OOP) terms: Encapsulation ...................................................................…13 / 14
Question 13: (a) Define these Object-Oriented Programming (OOP) terms: Instance ........................................................................…14 / 14

Mark scheme13 answers

Answers below. Sit the paper first if you are practising.

Pastlit

Computer Science 9618 · Programming Paradigms — Paper 3

A Level · topical answer key — answer key (teacher use)

Question

Answer

Marks

1Mark scheme for question 18
2Mark scheme for question 28
3Mark scheme for question 38
4Mark scheme for question 44
5Mark scheme for question 54
6Mark scheme for question 66
7Mark scheme for question 711
8Mark scheme for question 87
9Mark scheme for question 96
10Mark scheme for question 1011
11Mark scheme for question 118
12Mark scheme for question 126
13Mark scheme for question 138
QuestionAnswerMarksFrom
1see sheet89618/31 May/June 2021
2see sheet89618/32 May/June 2021
3see sheet89618/33 May/June 2021
4see sheet49618/31 Oct/Nov 2021
5see sheet49618/32 Oct/Nov 2021
6see sheet69618/31 May/June 2022
7see sheet119618/31 May/June 2022
8see sheet79618/32 May/June 2022
9see sheet69618/33 May/June 2022
10see sheet119618/33 May/June 2022
11see sheet89618/31 Oct/Nov 2022
12see sheet69618/32 Oct/Nov 2022
13see sheet89618/33 Oct/Nov 2022

Another paper, or another topic

Paper
Paper 313 questionsPaper 4questions coming

All of Topic 20

Questions as text

Q1 · Describe what is meant by an imperative (procedural) programming language 9618/31 May/June 2021

9 (a) Describe what is meant by an imperative (procedural) programming language. … … … … [2] (b) Describe what is meant by a declarative programming language. … … … … [2] (c) Identify the programming paradigm for each of these program code examples. Program code example Programming paradigm male(john). female(ethel). parent(john, ethel). FOR Counter = 1 TO 20 X = X * Counter NEXT Counter Start: LDD Counter INC ACC STO Counter public class Vehicle { private speed; public Vehicle() { speed = 0; } } [4]

8 marks

Mark scheme: 9(a) One mark for each correct marking point (Max 2) 2 • Imperative languages use variables • … which are changed using (assignment) statements • … they rely on a method of repetition / iteration. • The statements provide a sequence of commands for the computer to perform • … in the order written / given • … each line of code changes something in the program run. 9(b) One mark for each correct marking point (Max 2) 2 • Instructs a program on what needs to be done instead of how to do it • ... using facts and rules • … using queries to satisfy goals. • Can be logical or functional • Logical - states a program as a set of logical relations • Functional – constructed by applying functions to arguments / uses a mathematical style 9(c) One mark for each correct programming paradigm (Max 4) 4 Program code example Programming paradigm male(john). female(ethel). Declarative parent(john, ethel). FOR Counter = 1 TO 20 X = X * Counter Procedural / imperative NEXT Counter Start: LDD Counter INC ACC Low-level / assembly STO Counter public class Vehicle { private speed; public Vehicle() Object oriented / (OOP) { speed = 0; } }

This question in 9618/31 May/June 2021

Q2 · Describe what is meant by an imperative (procedural) programming language 9618/32 May/June 2021

9 (a) Describe what is meant by an imperative (procedural) programming language. … … … … [2] (b) Describe what is meant by a declarative programming language. … … … … [2] (c) Identify the programming paradigm for each of these program code examples. Program code example Programming paradigm male(john). female(ethel). parent(john, ethel). FOR Counter = 1 TO 20 X = X * Counter NEXT Counter Start: LDD Counter INC ACC STO Counter public class Vehicle { private speed; public Vehicle() { speed = 0; } } [4]

8 marks

Mark scheme: 9(a) One mark for each correct marking point (Max 2) 2 • Imperative languages use variables • … which are changed using (assignment) statements • … they rely on a method of repetition / iteration. • The statements provide a sequence of commands for the computer to perform • … in the order written / given • … each line of code changes something in the program run. 9(b) One mark for each correct marking point (Max 2) 2 • Instructs a program on what needs to be done instead of how to do it • ... using facts and rules • … using queries to satisfy goals. • Can be logical or functional • Logical - states a program as a set of logical relations • Functional – constructed by applying functions to arguments / uses a mathematical style 9(c) One mark for each correct programming paradigm (Max 4) 4 Program code example Programming paradigm male(john). female(ethel). Declarative parent(john, ethel). FOR Counter = 1 TO 20 X = X * Counter Procedural / imperative NEXT Counter Start: LDD Counter INC ACC Low-level / assembly STO Counter public class Vehicle { private speed; public Vehicle() Object oriented / (OOP) { speed = 0; } }

This question in 9618/32 May/June 2021

Q3 · Describe what is meant by an imperative (procedural) programming language 9618/33 May/June 2021

9 (a) Describe what is meant by an imperative (procedural) programming language. … … … … [2] (b) Describe what is meant by a declarative programming language. … … … … [2] (c) Identify the programming paradigm for each of these program code examples. Program code example Programming paradigm male(john). female(ethel). parent(john, ethel). FOR Counter = 1 TO 20 X = X * Counter NEXT Counter Start: LDD Counter INC ACC STO Counter public class Vehicle { private speed; public Vehicle() { speed = 0; } } [4]

8 marks

Mark scheme: 9(a) One mark for each correct marking point (Max 2) 2 • Imperative languages use variables • … which are changed using (assignment) statements • … they rely on a method of repetition / iteration. • The statements provide a sequence of commands for the computer to perform • … in the order written / given • … each line of code changes something in the program run. 9(b) One mark for each correct marking point (Max 2) 2 • Instructs a program on what needs to be done instead of how to do it • ... using facts and rules • … using queries to satisfy goals. • Can be logical or functional • Logical - states a program as a set of logical relations • Functional – constructed by applying functions to arguments / uses a mathematical style 9(c) One mark for each correct programming paradigm (Max 4) 4 Program code example Programming paradigm male(john). female(ethel). Declarative parent(john, ethel). FOR Counter = 1 TO 20 X = X * Counter Procedural / imperative NEXT Counter Start: LDD Counter INC ACC Low-level / assembly STO Counter public class Vehicle { private speed; public Vehicle() Object oriented / (OOP) { speed = 0; } }

This question in 9618/33 May/June 2021

Q4 · Draw one line from each programming paradigm to its most appropriate description 9618/31 Oct/Nov 2021

2 Draw one line from each programming paradigm to its most appropriate description. Programming paradigm Description Programs using the instruction set of a processor Declarative Programs based on events such as user actions or sensor outputs Imperative Programs using the concepts of class, inheritance, encapsulation and polymorphism Low-level Programs with an explicit sequence of commands that update the program state, Object-oriented with or without procedure calls Programs that specify the desired result rather than how to get to it [4]

4 marks

Mark scheme: 2 One mark for each single correct line from Programming Paradigm to 4 Description Programming Paradigm Description Programs using the instruction set of a processor Declarative Programs based on events such as user actions or sensor outputs Imperative Programs using the concepts of class, inheritance, encapsulation and Low-level polymorphism Programs with an explicit sequence of commands that update the program Object oriented state, with or without procedure calls Programs that specify the desired result rather than how to get to it

This question in 9618/31 Oct/Nov 2021

Q5 · Draw one line from each programming paradigm to its most appropriate description 9618/32 Oct/Nov 2021

2 Draw one line from each programming paradigm to its most appropriate description. Programming paradigm Description Programs using the instruction set of a processor Declarative Programs based on events such as user actions or sensor outputs Imperative Programs using the concepts of class, inheritance, encapsulation and polymorphism Low-level Programs with an explicit sequence of commands that update the program state, Object-oriented with or without procedure calls Programs that specify the desired result rather than how to get to it [4]

4 marks

Mark scheme: 2 One mark for each single correct line from Programming Paradigm to 4 Description Programming Paradigm Description Programs using the instruction set of a processor Declarative Programs based on events such as user actions or sensor outputs Imperative Programs using the concepts of class, inheritance, encapsulation and Low-level polymorphism Programs with an explicit sequence of commands that update the program Object oriented state, with or without procedure calls Programs that specify the desired result rather than how to get to it

This question in 9618/32 Oct/Nov 2021

Q6 · A declarative language is used to represent the following facts about cats 9618/31 May/June 2022

2 A declarative language is used to represent the following facts about cats. 01 type(leopard, wild). 02 type(lion, wild). 03 type(cheetah, wild). 04 type(savannah, hybrid). 05 type(persian, domestic). 06 07 hair(leopard, medium). 08 hair(lion, short). 09 hair(cheetah, medium). 10 hair(savannah, medium). 11 hair(persian, long). 12 13 spots(leopard, yes). 14 spots(lion, no). 15 spots(cheetah, yes). 16 spots(savannah, yes). 17 spots(persian, no). These clauses have the following meaning: Clause Meaning 01 A leopard is a type of wild cat. 08 A lion has short hair. 16 A savannah has spots. (a) More facts are to be included. A caracal is a wild cat with short hair. Write the additional clauses to record these facts. 18 … 19 … [2] (b) Using the variable Cat, the goal: hair(Cat, medium) returns Cat = leopard, cheetah, savannah Write the result returned by the goal: hair(Cat, long) Cat = … [1] (c) (i) Write the goal, using the variable Pet, to find all the domestic cats. … … [1] (ii) Write the goal, using the variable WildSpotty, to find all the wild cats with spots. … … … … [2]

6 marks

Mark scheme: 2(a) hair(caracal, short). 2 2(b) persian 1 2(c)(i) type(Pet, domestic). 1 2(c)(ii) spots(WildSpotty, yes) ,type(WildSpotty, wild). 2

This question in 9618/31 May/June 2022

Q7 · A program is to be written using Object-Oriented Programming (OOP) for a shop that sells… 9618/31 May/June 2022

7 A program is to be written using Object-Oriented Programming (OOP) for a shop that sells knitting yarn. There are three types of yarn: acrylic, wool or mix. The following data are stored for each type. • Name • Colour • Batch code • Weight • Number of balls of yarn in stock (can be edited) • Type of yarn The following statements apply to yarn. • Acrylic can be soft or not soft. • Wool can be lamb, merino or alpaca. • Mix contains a percentage of acrylic. Each type of yarn has a method that will display all the information about the yarn. (a) Complete this class inheritance diagram to show the properties, methods and inheritance. Yarn Name: STRING Colour: STRING BatchCode: STRING Weight: INTEGER NumberBalls: INTEGER Type: STRING Constructor() EditNumberBalls() YarnInfo() Acrylic Wool Mix Percentage: INTEGER … … Constructor() YarnInfo() Constructor() Constructor() … … [5] (b) Describe what is meant by the terms properties, methods and inheritance. Properties … … … … Methods … … … … Inheritance … … … … [6]

11 marks

Mark scheme: 7(a) Acrylic has attribute Soft of type BOOLEAN Wool has attribute WoolType with suitable data type Acrylic and Wool have method YarnInfo() Acrylic, Wool and Mix at least one inherit (one arrow correct) from Yarn … … Acrylic, Wool and Mix all inherit (all arrows correct) from Yarn Yarn Name: STRING Colour: STRING BatchCode: STRING Weight: INTEGER NumberBalls: INTEGER Type: STRING Constructor() EditNumberBalls() YarnInfo() Mix Percentage: INTEGER Constructor() YarnInfo() Acrylic Soft: BOOLEAN Constructor() YarnInfo() Wool WoolType: STRING Constructor() YarnInfo() Question Answer Marks 7(b) Properties max 2:  the data items / attributes  the data types // characteristics  defined in a class Methods max 2:  the procedures/ functions / programmed instructions in a class / super class / base class  … implementing the behaviours  … that act on the properties / attributes Inheritance max 2:  Methods and properties / attributes contained in one class/ super class / base class  Are made available to / reused by another class/ derived class 6

This question in 9618/31 May/June 2022

Q8 · A declarative language is used to represent the following facts about a school 9618/32 May/June 2022

2 A declarative language is used to represent the following facts about a school. 01 teaches(alan, mathematics). 02 teaches(ioana, geography). 03 teaches(nina, history). 04 teaches(alan, statistics). 05 06 studies(ahmed, history). 07 studies(freya, history). 08 studies(kim, history). 09 studies(freya, geography). 10 studies(hua, mathematics). 11 studies(hua, statistics). 12 studies(hua, geography). 13 14 tutors(alan, kim). 15 tutors(alan, hua). 16 tutors(alan, freya). 17 tutors(nina, ahmed). These clauses have the following meaning: Clause Meaning 01 Alan teaches mathematics. 06 Ahmed studies history. 14 Alan is Kim’s tutor. (a) More facts are to be included. Sam studies history and Nina is his tutor. Write the additional clauses to record these facts. 18 … 19 … [2] (b) Using the variable Student, the goal: studies(Student, history) returns Student = freya, ahmed, kim Write the result returned by the goal: studies(Student, geography) Student = … [1] (c) Write the goal, using the variable X, to find all the students who have a tutor that teaches them. For example, Hua has Alan for a tutor and is also taught mathematics by Alan. … … … … [4]

7 marks

Mark scheme: 2(a) tutors(nina, sam). 2 2(b) freya, hua // hua, freya 1 2(c) one mark for correct use of X one mark for two other variables in correct positions one mark for three correct clauses in any order one mark for correct syntax teaches(R, S), studies(X, S), tutors(R, X). 4

This question in 9618/32 May/June 2022

Q9 · A declarative language is used to represent the following facts about cats 9618/33 May/June 2022

2 A declarative language is used to represent the following facts about cats. 01 type(leopard, wild). 02 type(lion, wild). 03 type(cheetah, wild). 04 type(savannah, hybrid). 05 type(persian, domestic). 06 07 hair(leopard, medium). 08 hair(lion, short). 09 hair(cheetah, medium). 10 hair(savannah, medium). 11 hair(persian, long). 12 13 spots(leopard, yes). 14 spots(lion, no). 15 spots(cheetah, yes). 16 spots(savannah, yes). 17 spots(persian, no). These clauses have the following meaning: Clause Meaning 01 A leopard is a type of wild cat. 08 A lion has short hair. 16 A savannah has spots. (a) More facts are to be included. A caracal is a wild cat with short hair. Write the additional clauses to record these facts. 18 … 19 … [2] (b) Using the variable Cat, the goal: hair(Cat, medium) returns Cat = leopard, cheetah, savannah Write the result returned by the goal: hair(Cat, long) Cat = … [1] (c) (i) Write the goal, using the variable Pet, to find all the domestic cats. … … [1] (ii) Write the goal, using the variable WildSpotty, to find all the wild cats with spots. … … … … [2]

6 marks

Mark scheme: 2(a) hair(caracal, short). 2 2(b) persian 1 2(c)(i) type(Pet, domestic). 1 2(c)(ii) spots(WildSpotty, yes) ,type(WildSpotty, wild). 2

This question in 9618/33 May/June 2022

Q10 · A program is to be written using Object-Oriented Programming (OOP) for a shop that sells… 9618/33 May/June 2022

7 A program is to be written using Object-Oriented Programming (OOP) for a shop that sells knitting yarn. There are three types of yarn: acrylic, wool or mix. The following data are stored for each type. • Name • Colour • Batch code • Weight • Number of balls of yarn in stock (can be edited) • Type of yarn The following statements apply to yarn. • Acrylic can be soft or not soft. • Wool can be lamb, merino or alpaca. • Mix contains a percentage of acrylic. Each type of yarn has a method that will display all the information about the yarn. (a) Complete this class inheritance diagram to show the properties, methods and inheritance. Yarn Name: STRING Colour: STRING BatchCode: STRING Weight: INTEGER NumberBalls: INTEGER Type: STRING Constructor() EditNumberBalls() YarnInfo() Acrylic Wool Mix Percentage: INTEGER … … Constructor() YarnInfo() Constructor() Constructor() … … [5] (b) Describe what is meant by the terms properties, methods and inheritance. Properties … … … … Methods … … … … Inheritance … … … … [6]

11 marks

Mark scheme: 7(a) Acrylic has attribute Soft of type BOOLEAN Wool has attribute WoolType with suitable data type Acrylic and Wool have method YarnInfo() Acrylic, Wool and Mix at least one inherit (one arrow correct) from Yarn … … Acrylic, Wool and Mix all inherit (all arrows correct) from Yarn Yarn Name: STRING Colour: STRING BatchCode: STRING Weight: INTEGER NumberBalls: INTEGER Type: STRING Constructor() EditNumberBalls() YarnInfo() Mix Percentage: INTEGER Constructor() YarnInfo() Acrylic Soft: BOOLEAN Constructor() YarnInfo() Wool WoolType: STRING Constructor() YarnInfo() Question Answer Marks 7(b) Properties max 2:  the data items / attributes  the data types // characteristics  defined in a class Methods max 2:  the procedures/ functions / programmed instructions in a class / super class / base class  … implementing the behaviours  … that act on the properties / attributes Inheritance max 2:  Methods and properties / attributes contained in one class/ super class / base class  Are made available to / reused by another class/ derived class 6

This question in 9618/33 May/June 2022

Q11 · Define these Object-Oriented Programming (OOP) terms: Instance … … Inheritance … …… 9618/31 Oct/Nov 2022

11 (a) Define these Object-Oriented Programming (OOP) terms: Instance … … Inheritance … … Polymorphism … … [3] (b) In OOP, a class contains attributes and methods. Complete the pseudocode for the class Car to enable objects to be created. The class needs to include: • string attributes to store the make, model, body type and fuel type • an integer attribute to store the number of cars of that type built. The attributes must be available only through the methods of the class. CLASS … PRIVATE Make : STRING PRIVATE … … … … PUBLIC PROCEDURE New(CarMake : STRING, … , … ) Make … ← Model … ← BodyType CarBodyType ← Fuel "" ← NumberBuilt 0 ← ENDPROCEDURE GetFuel() GetNumberBuilt() … [5]

8 marks

Mark scheme: 11(a) One mark for each correct OOP term definition: 3 • Instance – an occurrence of an object // a specific object based on the class // an instantiation of a class. • Inheritance – the capability of defining a new class of objects that has all the attributes and methods from a parent class. • Polymorphism – allows the same method to take on different behaviours depending on which class is instantiated // methods can be redefined for derived classes. 11(b) One mark for each point: 5 • Car and ENDCLASS • Four declarations – must use the identifiers used in the assignments • Constructor header – must use CarBodyType • Two assignments – must use CarMake • Constructor identifier for the car model and the identifier in the Model assignment statement match CLASS Car PRIVATE Make : STRING PRIVATE Model : STRING PRIVATE BodyType : STRING PRIVATE Fuel : STRING PRIVATE NumberBuilt : INTEGER PUBLIC PROCEDURE NEW (CarMake : STRING, CarModel : STRING, CarBodyType : STRING) Make  CarMake Model  CarModel BodyType  CarBodyType Fuel  "" NumberBuilt  0 ENDPROCEDURE getFuel() getNumberBuilt() ENDCLASS

This question in 9618/31 Oct/Nov 2022

Q12 · Define these Object-Oriented Programming (OOP) terms: Encapsulation … … Getter … … Setter… 9618/32 Oct/Nov 2022

10 (a) Define these Object-Oriented Programming (OOP) terms: Encapsulation … … Getter … … Setter … … [3] (b) A school has a program written using OOP to maintain its staff and student records. The object SubstituteTeacher allows the details of the school’s substitute teachers to be stored. This includes their full name, telephone number and whether or not they are in school today. For example: SubName Sarah Jones Telephone 01223658721 InSchool TRUE Complete the diagram for the object SubstituteTeacher, including appropriate properties and their getters and setters. SubstituteTeacher SubName : STRING … InSchool : BOOLEAN … SetTelephone(Tel : STRING) … GetSubName() … … [3]

6 marks

Mark scheme: 10(a) One mark for each correct OOP term definition 3 • Encapsulation – putting properties and methods inside a class // ensures sensitive data is hidden from users by hiding values of a structured data object inside a class. • Getter – method that is used to return the value of a property. • Setter – method that is used to update the value of a property. 10(b) One mark for each point 3 • properties correct • setters correct • getters correct SubstituteTeacher SubName : STRING Telephone : STRING InSchool : BOOLEAN SetSubName(StaffName : STRING) SetTelephone(Tel : STRING) SetInSchool(Present : BOOLEAN) GetSubName() GetTelephone() GetInSchool()

This question in 9618/32 Oct/Nov 2022

Q13 · Define these Object-Oriented Programming (OOP) terms: Instance … … Inheritance … …… 9618/33 Oct/Nov 2022

11 (a) Define these Object-Oriented Programming (OOP) terms: Instance … … Inheritance … … Polymorphism … … [3] (b) In OOP, a class contains attributes and methods. Complete the pseudocode for the class Car to enable objects to be created. The class needs to include: • string attributes to store the make, model, body type and fuel type • an integer attribute to store the number of cars of that type built. The attributes must be available only through the methods of the class. CLASS … PRIVATE Make : STRING PRIVATE … … … … PUBLIC PROCEDURE New(CarMake : STRING, … , … ) Make … ← Model … ← BodyType CarBodyType ← Fuel "" ← NumberBuilt 0 ← ENDPROCEDURE GetFuel() GetNumberBuilt() … [5]

8 marks

Mark scheme: 11(a) One mark for each correct OOP term definition: 3 • Instance – an occurrence of an object // a specific object based on the class // an instantiation of a class. • Inheritance – the capability of defining a new class of objects that has all the attributes and methods from a parent class. • Polymorphism – allows the same method to take on different behaviours depending on which class is instantiated // methods can be redefined for derived classes. 11(b) One mark for each point: 5 • Car and ENDCLASS • Four declarations – must use the identifiers used in the assignments • Constructor header – must use CarBodyType • Two assignments – must use CarMake • Constructor identifier for the car model and the identifier in the Model assignment statement match CLASS Car PRIVATE Make : STRING PRIVATE Model : STRING PRIVATE BodyType : STRING PRIVATE Fuel : STRING PRIVATE NumberBuilt : INTEGER PUBLIC PROCEDURE NEW (CarMake : STRING, CarModel : STRING, CarBodyType : STRING) Make  CarMake Model  CarModel BodyType  CarBodyType Fuel  "" NumberBuilt  0 ENDPROCEDURE getFuel() getNumberBuilt() ENDCLASS

This question in 9618/33 Oct/Nov 2022