Further programming: paradigms, OOP, files and exceptions – A Level Computer Science (9618)
36 questions · page 2 of 3 · Clear filters
Question text
9
A veterinary surgery wants to create a class for individual pets.
Some of the attributes required in the class are listed in the table.
Attribute
Data type
Description
PetID
STRING
unique ID assigned at registration
PetType
STRING
type of pet assigned at registration
telephone number of owner assigned at
OwnerTelephone
STRING
registration
DateRegistered
DATE
date of registration
(a) State one reason why the attributes would be declared as PRIVATE.
…
… [1]
(b) Complete the class diagram for Pet, to include:
•
an attribute and data type for the name of the pet
•
an attribute and data type for the name of the owner
•
a method to create a Pet object and set attributes at the time of registration
•
a method to assign a pet ID
•
a method to assign the date of registration
•
a method to return the pet name
•
a method to return the owner’s telephone number.
Pet
PetID
: STRING
PetType
: STRING
OwnerTelephone
: STRING
DateRegistered
: DATE
… : …
… : …
…
…
…
…
…
[5]
ĬÓĊ®Ġ´íÈõÏĪÅĊàùµĀ×
Question text
8
A declarative programming language is used to represent the features that are available and the
features that are unavailable on different body styles of a car.
01
feature(sunroof).
02
feature(automatic_tailgate).
03
feature(heated_seats).
04
feature(extra_seats).
05
feature(reversing_camera).
06
feature(dashboard_camera).
07
feature(air_conditioning).
08
feature(heated_windscreen).
09
feature(satnav).
10
bodystyle(saloon).
11
bodystyle(hatchback).
12
bodystyle(estate).
13
bodystyle(minivan).
14
bodystyle(convertible).
15
available(sunroof, hatchback).
16
available(sunroof, minivan).
17
available(reversing_camera, hatchback).
18
available(extra_seats, minivan).
19
available(reversing_camera, saloon).
20
unavailable(sunroof, convertible).
21
unavailable(automatic_tailgate, saloon).
22
unavailable(extra_seats, hatchback).
These clauses have the meanings:
Clause
Meaning
01
Sunroof is a feature.
10
Saloon is a body style.
15
Sunroof is available on a hatchback.
20
Sunroof is unavailable on a convertible.
(a) Sliding doors is a feature that is available on a minivan but unavailable on a hatchback.
Write additional clauses to represent this information.
23 …
24 …
25 …
[3]
(b) Using the variable Options, the goal:
available(Options, saloon)
returns
Options = reversing_camera
Write the result returned by the goal:
available(Options, hatchback)
Options = … [1]
(c) F may be available for B if F is a feature and B is a body style and F is not unavailable for that
body style.
Write this as a rule:
may_choose_option(F, B)
IF …
…
…
… [4]
Question text
10 A declarative programming language is used to allow clients to choose daily activities at the
beach.
01
activity(paddleboarding).
02
activity(sailing).
03
activity(rowing).
04
activity(kayaking).
05
activity(jetskiing).
06
client(stevie).
07
client(antonio).
08
client(henry).
09
client(eliza).
10
client(rebeka).
11
client(danny).
12
client(erik).
13
client(simone).
14
client(petra).
15
client(frankie).
16
choice(petra, rowing).
17
choice(frankie, sailing).
18
choice(erik, sailing).
19
choice(eliza, rowing).
20
choice(stevie, jetskiing).
21
choice(henry, sailing).
22
done(henry, jetskiing).
23
done(rebeka, jetskiing).
24
done(antonio, kayaking).
These clauses have the meanings:
Clause
Meaning
01
Paddle boarding is an activity.
06
Stevie is a client.
16
Petra has chosen rowing.
22
Henry has already done jet skiing.
(a) Jane is a client who would like to choose the activity surfing and she has already done sailing.
Write additional clauses to represent this information.
25 …
26 …
27 …
28 …
[4]
(b) Using the variable List, the goal:
choice(List, rowing)
returns
List = petra, eliza
Write the result returned by the goal:
choice(List, sailing)
List = … [1]
(c) C is a client who would like to choose A if A is an activity and C has not already done A.
Write this as a rule:
may_choose_activity(C, A)
IF …
…
…
… [4]
Question text
8
A declarative programming language is used to represent the features that are available and the
features that are unavailable on different body styles of a car.
01
feature(sunroof).
02
feature(automatic_tailgate).
03
feature(heated_seats).
04
feature(extra_seats).
05
feature(reversing_camera).
06
feature(dashboard_camera).
07
feature(air_conditioning).
08
feature(heated_windscreen).
09
feature(satnav).
10
bodystyle(saloon).
11
bodystyle(hatchback).
12
bodystyle(estate).
13
bodystyle(minivan).
14
bodystyle(convertible).
15
available(sunroof, hatchback).
16
available(sunroof, minivan).
17
available(reversing_camera, hatchback).
18
available(extra_seats, minivan).
19
available(reversing_camera, saloon).
20
unavailable(sunroof, convertible).
21
unavailable(automatic_tailgate, saloon).
22
unavailable(extra_seats, hatchback).
These clauses have the meanings:
Clause
Meaning
01
Sunroof is a feature.
10
Saloon is a body style.
15
Sunroof is available on a hatchback.
20
Sunroof is unavailable on a convertible.
(a) Sliding doors is a feature that is available on a minivan but unavailable on a hatchback.
Write additional clauses to represent this information.
23 …
24 …
25 …
[3]
,
,
(b) Using the variable Options, the goal:
available(Options, saloon)
returns
Options = reversing_camera
Write the result returned by the goal:
available(Options, hatchback)
Options = … [1]
(c) F may be available for B if F is a feature and B is a body style and F is not unavailable for that
body style.
Write this as a rule:
may_choose_option(F, B)
IF …
…
…
… [4]
Question text
8
(a) A pseudocode algorithm finds a customer account record in a random file and outputs it. The
records are stored using the user-defined data type TAccount.
TYPE TAccount
DECLARE AccountNumber : INTEGER
DECLARE LastName : STRING
DECLARE FirstName : STRING
DECLARE Address : STRING
DECLARE ContactNumber : STRING
ENDTYPE
Complete the file handling pseudocode.
The function Hash() takes the customer account number as a parameter, calculates and
returns the hash value.
DECLARE Customer : TAccount
DECLARE Location : INTEGER
DECLARE AccountFile : STRING
…
"AccountRecords.dat"
… AccountFile …
OUTPUT "Please enter an account number"
INPUT Customer.AccountNumber
Hash( … )
Location
SEEK … , Location
… AccountFile, …
OUTPUT Customer
// output customer record
CLOSEFILE AccountFile
[5]
(b) Define the term exception handling.
…
… [1]
(c) State two possible causes of an exception.
…
… [2]
Question text
11
A declarative programming language is used to represent subjects that students can choose to
study.
Students must choose two subjects.
01 subject(mathematics).
02 subject(physics).
03 subject(chemistry).
04 subject(computer_science).
05 subject(geography).
06 subject(history).
07 subject(english).
08 subject(biology).
09 student(tomaz).
10 student(josephine).
11 student(elspeth).
12 student(nico).
13 student(teresa).
14 student(pietre).
15 choice1(tomaz, mathematics).
16 choice1(teresa, chemistry).
17 choice1(pietre, mathematics).
18 choice1(nico, mathematics).
19 choice1(elspeth, chemistry).
20 choice2(tomaz, computer_science).
21 choice2(nico, geography).
These clauses have the meanings:
Clause
Meaning
01
Mathematics is a subject.
09
Tomaz is a student.
15
Tomaz has chosen mathematics as his first choice.
20
Tomaz has chosen computer science as his second choice.
(a) Anthony is a student who would like to study history and geography.
Write additional clauses to represent this information.
22 …
23 …
24 …
[3]
(b) Using the variable X, the goal:
choice1(X, chemistry)
returns
X = teresa, elspeth
Write the result returned by the goal:
choice1(X, mathematics)
X = … [1]
(c) Students must choose two different subjects such that:
N may choose S, if N is a student and S is a subject and N has not chosen S as the first
choice.
Write this as a rule.
may_choose_subject(N, S)
IF …
…
…
… [4]
Question text
11
A declarative programming language is used to represent some facts about people and their
hobbies.
01 hobby(music).
02 hobby(caving).
03 hobby(climbing).
04 hobby(camping).
05 hobby(baking).
06 hobby(travelling).
07 person(toby).
08 person(natasha).
09 person(fatima).
10 person(joseph).
11 person(elijah).
12 person(nina).
13 enjoys(natasha, travelling).
14 enjoys(toby, climbing).
15 enjoys(nina, climbing).
16 enjoys(elijah, camping).
17 enjoys(fatima, baking).
18 enjoys(joseph, camping).
19 dislikes(toby, caving).
These clauses have the meanings:
Clause
Meaning
01
Music is a hobby
07
Toby is a person
13
Natasha enjoys travelling
19
Toby dislikes caving
(a) Carlos is a person who enjoys the hobby of cycling but does not like music.
Write additional clauses to represent this information.
20 …
21 …
22 …
23 …
[4]
(b) Using the variable P, the goal:
enjoys(P, camping)
returns
P = elijah, joseph
Write the result returned by the goal:
enjoys(P, climbing)
P = … [1]
(c) N is a person who might enjoy H if H is a hobby and N does not dislike H.
Write this as a rule.
might_enjoy(N, H)
IF …
…
…
… [4]
Question text
12 (a) Describe, with an example, what is meant by an exception.
…
…
…
… [2]
(b) A pseudocode algorithm searches for a customer record
in
a
random
file
AccountRecord.dat. A user inputs the name of the customer.
The records are stored using the user‑defined data type TAccount.
TYPE TAccount
DECLARE AccountNumber : INTEGER
DECLARE Name : STRING
DECLARE Address : STRING
DECLARE Telephone : STRING
ENDTYPE
If the record is found, it is output, otherwise an error message is displayed.
Complete the file handling pseudocode.
DECLARE Customer : TAccount
DECLARE Location : INTEGER
DECLARE MaxSize : INTEGER
DECLARE FoundFlag : BOOLEAN
DECLARE SearchCustomer : STRING
MaxSize
1000
OPENFILE …
Location
1
…
FALSE
OUTPUT "Enter the customer’s name"
…
… AND Location <= MaxSize
… "AccountRecord.dat", …
GETRECORD "AccountRecord.dat", Customer
IF SearchCustomer = Customer.Name THEN
OUTPUT "Customer found: "
OUTPUT Customer
// output customer record
FoundFlag
TRUE
ENDIF
Location
Location + 1
ENDWHILE
IF NOT FoundFlag THEN
OUTPUT " … "
ENDIF
[7]
Permission to reproduce items where third‑party owned material protected by copyright is included has been sought and cleared where possible. Every
publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer‑related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.
Cambridge Assessment International Education is part of Cambridge Assessment. Cambridge Assessment is the brand name of the University of Cambridge
Question text
10 The pseudocode algorithm shown copies an active accounts text file ActiveFile.txt to an
archive accounts text file ArchiveFile.txt, one line at a time. Any blank lines found in the
active accounts text file are replaced with the words "Account not present" in the archive
accounts text file.
Complete this file-handling pseudocode.
DECLARE Account : STRING
…
OPENFILE "ArchiveFile.txt" FOR WRITE
WHILE NOT …
READFILE "ActiveFile.txt", Account
IF Account = "" THEN
WRITEFILE "ArchiveFile.txt", " … "
ELSE
WRITEFILE "ArchiveFile.txt", …
ENDIF
ENDWHILE
…
CLOSEFILE "ArchiveFile.txt"
[5]
Question text
4
Draw one line from each Object‑Oriented Programming (OOP) term to its most appropriate
description.
OOP term
Description
methods used to return the value of
a property
Encapsulation
the process of putting data and
methods together as a single unit
Getters
methods used to update the value of
a property
Polymorphism
allows methods to be redefined for
derived classes
Setters
enables the defining of a new class
that inherits from a parent class
[4]
Question text
6
(a) Write pseudocode statements to declare the composite data type, TAppointments, to hold
data about patients for a dental clinic. It will include for each patient:
•
name (first name and last name)
•
date of birth
•
telephone number
•
date of last appointment
•
date of next appointment
•
all treatments are complete (yes or no).
…
…
…
…
…
…
…
… [4]
(b) This pseudocode algorithm reads dental records stored in a random file using the user‑defined
data type TAppointments and prints the contents of the file, one record at a time.
Complete this file handling pseudocode:
DECLARE DentalRecord : ARRAY[1:250] OF TAppointments
DECLARE DentalFile : STRING
DECLARE Count : INTEGER
"DentalFile.dat"
DentalFile
OUTPUT "The file ", DentalFile, " contains these records:"
OPENFILE …
…
1
REPEAT
SEEK DentalFile, Count
…
OUTPUT DentalRecord[Count]
Count + 1
Count
… (DentalFile)
…
[5]
Question text
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]
Question text
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]
Question text
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]
Question text
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]