JPJC 2024 JC2 Prelim Paper 2 QP
Uploaded by Kozak327 · 25 August 2026
Preview
Text from the first pages1 Name:____________________________________ Class:____________ JURONG PIONEER JUNIOR COLLEGE JC2 Preliminary Examination 2024 COMPUTING 9569/02 Higher 2 14 August 2024 Paper 2 (Practical) 3 hours Additional materials: Cover Page Electronic version of TASK1.txt data file Electronic version of TASK3.txt data file Electronic version of TASK4.txt data file Insert Quick Reference Guide READ THESE INSTRUCTIONS FIRST Answer all the questions. 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. Approved calculators are allowed. Save each task as it is completed. 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 number of marks is given in brackets [ ] at the end of each task. The total number of marks for this paper is 100. This document consists of 13 printed pages. [Turn over
2 Instructions to candidates: Your program code and output for each of Task 1 to 4 should be downloaded in a single.ipynb file. For example, your program code and output for Task 1 should be downloaded as TASK1_<your class>_<your name>.ipynb. 1 Name your Jupyter Notebook as: TASK1_<your class>_<your name>.ipynb The task is to implement a Vigenère cipher encryption algorithm. The Vigenère cipher is a method of encrypting alphabetic text by using a simple form of polyalphabetic substitution. A key is repeated to match the length of the plaintext, and each letter in the plaintext is shifted according to the corresponding letter in the key. For example: The plain text is “HELLO WORLD” and the key is “ABLE”. The key, repeated to match the 11 characters in the text including spaces, is “ABLEABLEABL”. Each letter in both the plain text and key is first converted to a number (A=0, B=1, C=2, D=3, E=4, F=5, ..., Z=25). This is to be done with the help of ASCII values. The two numbers are then added up to give the encrypted letter. First letter ‘H’ in the plain text is number 7 and first letter ‘A’ in the key is number 0. Calculate 7 + 0 = 7. Hence, the first encrypted letter is ‘H’. Second letter ‘E’ in the plain text is number 4 and second letter ‘B’ in the key is number 1. Calculate 4 + 1 = 5. Hence, the second encrypted letter is ‘F’. When a letter goes beyond ‘Z’, it returns to ‘A’. Use modular arithmetic with modulus 26 to wrap around if necessary. Space is replaced with the character ‘!’. Plaintext character H E L L O W O R L D Key character A B L E A B L E A B L Encrypted character H F W P O ! H S R M O The resulting encrypted text is “HFWPO!HSRMO”. Task 1.1 Write a function CharToNum() that takes an uppercase letter as parameter and returns an integer corresponding to its position in the alphabet, where ‘A’=0, ‘B’=1, ‘C’=2, ..., ‘Z’=25. You are required to use ASCII encoding in your implementation. [2]
3 Task 1.2 Write a function encrypt() that takes a string text and a string key as input parameters. The encrypt() function returns an encrypted string where each letter in text is shifted forward by the corresponding letter in key. You are required to use the function from Task 1.1 in your implementation. Assume both the text and key contain only uppercase letters, and spaces are allowed in the text. No other characters are in the text and key. [7] Task 1.3 The text file TASK1.txt contains messages that needs to be encrypted. Thereafter, the encrypted messages are stored in a text file named ENCRYPTED.txt. Write the program code to: Read the data from the text file TASK1.txt The key is “JPJC” Use your function from Task 1.2 to encrypt the content Write the encrypted messages to the text file ENCRYPTED.txt Test your program with the plain text in the file TASK1.txt. Display the content of ENCRYPTED.txt after you have run the program. Save your Jupyter Notebook for Task 1. [3] [1] [Turn over
4 2 Name your Jupyter Notebook as: TASK2_<your class>_<your name>.ipynb A programmer is writing Coconut Island Game to be played on the computer. The island is represented as a rectangular grid, 10 rows by 15 columns. Each square of land on the island is represented by a pair of coordinates in a 2D array. The top left square of the island has coordinates where row = 0 and column = 0. There are 10 squares of land down and 15 squares of land across. The computer will: generate three random locations where coconut trees will be located start player at the top left corner of the grid (row = 0, column = 0) prompt the player for the move, in the format direction left (L), right (R), up (U), down (D), followed by a space and the distance representing the number of grids moved in the chosen direction (e.g.: R 6 would move the player six grids to the right from the current location) plot the path the player has moved display the contents of the array by outputting for each square of land: '.' for unexplored land 'C' for coconut tree 'E' for eaten coconut when player’s move ends on a coconut tree '*' for explored land i.e. path walked on by player The rule of the game is: player has maximum eight moves to win the game, the player needs to o visit the three squares with coconut trees to eat them, and o reach the finish point at bottom right corner (row = 9, column = 14) A sample grid of the island, with three coconut trees, is displayed: MAP of Coconut Island * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C . . . . . C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Starting point Finish point
5 The following is a sample run of the game: Welcome to Coconut Island Game! * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C . . . . . C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . You are at position: (0, 0) Coconut eaten: 0 Enter your move (L/R/U/D distance): D 3 * . . . . . . . . . . . . . . * . . . . . . . . . . . . . . * . . . . . . . . . . . . . . E . . . . . C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . You are at position: (3, 0) Coconut eaten: 1 Enter your move (L/R/U/D distance): R 6 * . . . . . . . . . . . . . . * . . . . . . . . . . . . . . * . . . . . . . . . . . . . . E * * * * * E . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . You are at position: (3, 6) Coconut eaten: 2 Enter your move (L/R/U/D distance): D 3 * . . . . . . . . . . . . . . * . . . . . . . . . . . . . . * . . . . . . . . . . . . . . E * * * * * E . . . . . . . . . . . . . . * . . . . . . . . . . . . . . * . . . . . . . . . . C . . . * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . You are at position: (6, 6) Coconut eaten: 2 [Turn over Enter your move (L/R/U/D distance): L 4
6 * . . . . . . . . . . . . . . * . . . . . . . . . . . . .
Content continues in the PDF. Download PDF
Related notes
- JPJC 2024 JC2 Prelim Paper 2 MS v2Exam Papers · 2024
- JPJC 2024 JC2 Year-End Exam H2 Computing Paper 1Exam Papers · 2024
- JPJC 2024 JC2 Year-End Exam H2 Computing Paper 1 Marking SchemeExam Papers · 2024
- 2024 ASR H2 Computing Prelim P1 SolExam Papers · 2024
- 2024 ASR H2 Computing Prelim P1 QnsExam Papers · 2024
- 2025 VJC H2 Computing Prelim Paper 1Exam Papers · 2025
- 2025 VJC H2 Computing Prelim Paper 1 SolutionsExam Papers · 2025
- 2025 TJC H2 Computing Prelim Paper 1 SolutionsExam Papers · 2025
- RVHS 2025 H2 Computing Prelim Paper 1Exam Papers · 2025
- RVHS 2025 H2 Computing Prelim Paper 1 SolutionsExam Papers · 2025
- RI 2025 H2 Computing Prelim Paper 1Exam Papers · 2025
- RI 2025 H2 Computing Prelim Paper 1 SolutionsExam Papers · 2025
- See all H2 Computing notes

