9569/02 Computing
9569/02 Computing
in collaboration with
CAMBRIDGE ASSESSMENT INTERNATIONAL EDUCATION
General Certificate of Education Advanced Level
Higher 2
All tasks must be done in the computer laboratory. You are not allowed to bring in or take out any pieces of
work or materials on paper or electronic media or in any other form.
The use of built-in functions, where appropriate, is allowed for this paper unless stated otherwise.
Note that up to 6 marks out of 100 will be awarded for the use of common coding standards for programming
style.
The numbers of marks is given in brackets [ ) at the end of each question or part question.
The total number of marks for this paper is 100.
Instruction to candidates:
Your program code and output for each of Task 1 to 4.3 should be saved in a single . ipynb file using
Jupyter Notebook. For example, your program code and output for Task 1 should be saved as:
Make sure that each of your . ipynb files shows the required output in Jupyter Notebook.
A Caesar cypher encodes each letter with a different letter. A 10-place Caesar cypher uses the
ASCII value of each letter and adds the number 10 to it.
For example:
• The letter 'A' has the ASCII value 65. Adding 10 to the number will give the ASCII value 75.
The character for 75 is 'K'.
• When an uppercase letter's code goes beyond 'Z' it returns to '/\. For example, the character
'Z' will be encrypted as 'J'.
• When a lowercase letter's code goes beyond 'z' it returns to 'a'. For example, the character 'x'
will be encrypted as 'h'.
• Spaces ' ' are replaced with the character'!'.
You will only need to convert letters and spaces. If the character is invalid, -1 is returned.
The following table shows the ASCII values of some of the characters.
A 65
z 90
a 97
z 122
''(space) 32
! 33
In ASCII the letters follow on numerically. For example, the letter'/\ is 65, 'B' is 66, 'C' is 67 etc.
For each of the sub-tasks, add a comment statement at the beginning of the code, using the hash
symbol '#' to indicate the sub-task the progran:, code belongs to, for example:
In [ 1] : #Task 1. 1
I Program code
Output:
Task 1.1
This program will encrypt each letter by adding the number 10 to its ASCII value. Spaces will be
replaced with '!'. If the character is invalid, -1 is returned.
Write program code for a function that takes a character as a parameter and returns the ASCII
value of the new encrypted character. [5]
Task 1.2
A
a
#
' ' (space) [2]
Task 1.3
The text file DATATOENCRYPT. txt contains a message that needs to be encrypted and then
stored in a text file named ENCRYPTEDMESSAGE. txt
Show the contents of ENCRYPTEDMESSAGE. txt after you have run the program. [11
This task is to perform sorting algorithms on 100 integers held in a 1-dimensional list and then
search for a value in the list.
For each of the sub-tasks, add a comment statement at the beginning of the code using the hash
symbol '#', to indicate the sub-task the program code belongs to, for example:
In [ 1] : I
#Task 2 .1
Program code
Output:
Task 2.1
Task 2.2
Task 2.3
• ask the user to select which sorting algori.thm they want to use
• loop until a valid choice is input
• call your function from Task 2.1
• call the appropriate sorting procedure
• output the sorted list. [7]
Test the program by first entering one invalid choice (for example, 'no') and then by entering one
of the sorting methods (f~r example, 'bubble'). [1]
© UCLES & MOE 2022 9569/02/O/N/22
5
Task 2.4
Test the program with the smallest integer that is in the list and then with one integer that is not in
the list. [2]
A binary search tree is used to store 10 integer values between O and 999 (inclusive) in ascending
numerical order.
• a constructor to set the left pointer and right pointer to None, and the data to its parameter
• a recursive method to take the parameter and store it in the correct position in the tree
• a recursive method to use in-order traversal to output the data in the tree
• a recursive method to use post-order traversal to output the data in the tree.
For the sub-task, add a comment statement at the beginning of the code using the hash symbol
'#', to indicate the sub-task the program code belongs to, for example:
Output:
Task 3.1
Write program code to declare the class Tree and its constructor. [4]
Write the recursive method to insert a new node into the tree. [6]
• declare the method to output the in-order traversal of the binary tree
• declare the method to output the post-order traversal of the binary tree.
Call the in-order and post-order methods using your tree structure. [7]
Test your program and show the output from each traversal. [2]
A library currently keeps paper records about its members, books and the books loaned. The
library wants to create a suitable database to store the data and to allow them to run searches for
specific data. The database will have three tables: a table to store data about the books, a table
about the members and a table about the loans. The fields in each table are:
Book:
Member:
Loan:
For each of the sub-tasks 4.1 to 4.3, add a comment statement at the beginning of the code using
the hash symbol '#', to indicate the sub-task the program code belongs to, for example:
In [ 1] : I #Task 4.1
Program code
Output:
Task 4.1
Write a Python program that uses SQL code to create the database LIBRARY with the three
tables given. Define the primary and foreign keys for each table. [6]
Task 4.2
The text files BOOK. txt, MEMBER. txt and LOAN. txt store the comma-separated values for
each of the tables in the database.
Write a Python program to read in the data from each file and then store each item of data in the
correct place in the database. [5]
Task 4.3
Write a Python program to input a member's number and return the names of all the books that
they have had out on loan, and whether each book has been returned. [5]
Test your program by running the application with the member number 200 [2]
Task 4.4
Write a Python program and the necessary files to create a web application, that displays the
following data, about books that have not yet been returned:
The program should return an HTML document that enables the web browser to display a table
with the required data.
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the
publisher will be pleased to make amends at the earliest possible opportunity.
Cambridge Assessment International Education is part of Cambridge Assessment. Cambridge Assessment is the brand name of the University of Cambridge
Local Examinations Syndicate (UCLES), which is a department of the University of Cambridge.