Further programming: paradigms, OOP, files and exceptions – A Level Computer Science (9618)
16 questions · page 1 of 2 · Clear filters
Question text
10 Explain what is meant by exception handling.
Include an example of a possible cause of an exception in your answer.
Explanation …
…
…
…
Example …
[3]
ĬÙú¾Ġ´íÈõÏĪÅĊàû·þ×
Question text
10 An exception is an error that may cause a program to halt unexpectedly.
(a) Describe how program termination due to an exception can be avoided.
…
…
…
…
… [2]
(b) Identify two possible causes of exceptions.
1 …
…
2 …
…
[2]
ĬÓĊ®Ġ´íÈõÏĪÅĊßùµĀ×
Question text
12 An exception can occur when running a program.
(a) Explain what is meant by an exception.
…
…
…
…
…
… [3]
(b) Identify one example of an exception and give one reason why the exception may cause a
problem.
Example …
…
Reason …
…
[2]
ĬÛú¾Ġ´íÈõÏĪÅĊàû¶Ā×
Question text
3
(a) Describe circuit switching as a method of data transmission.
…
…
…
…
…
… [3]
(b) State one benefit and one drawback of circuit switching as a method of data transmission.
Benefit …
…
Drawback …
…
[2]
ĬÏĊ®Ġ´íÈõÏĪÅĊÞú¸þ×
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
10 Objects and classes form the basic structure of Object‑Oriented Programming (OOP).
(a) Outline the structure of a class.
…
…
…
…
…
… [3]
(b) Give three differences between an object and a class.
1 …
…
…
2 …
…
…
3 …
…
…
[3]
ĬÓĊ®Ġ´íÈõÏĪÅĊÞû¸þ×
Question text
3
(a) Describe circuit switching as a method of data transmission.
…
…
…
…
…
… [3]
(b) State one benefit and one drawback of circuit switching as a method of data transmission.
Benefit …
…
Drawback …
…
[2]
ĬÏĊ®Ġ´íÈõÏĪÅĊÝû¸þ×
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) 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
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
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,
with or without procedure calls
Object-oriented
Programs that specify the desired result
rather than how to get to it
[4]