2023 HCI P2 Question Paper
Uploaded by Kozak327 · 8 September 2026
Preview
Text from the first pagesThis document consists of 12 printed pages. HWA CHONG INSTITUTION C2 PRELIMINARY EXAMINATION 2023 COMPUTING Higher 2 23 AUG 2023 Paper 2 (9569 / 02) 1400 -- 1700 hrs Additional Materials: Electronic version of MAZE.txt data file Electronic version of PERSON.txt data file Electronic version of CHESS.csv data file Electronic version of DONUT.txt data file Electronic version of MEMBER.txt data file Electronic version of SALE.txt data file Insert Quick Reference Guide READ THESE INSTRUCTIONS FIRST Answer all 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 question or part question. The total number of marks for this paper is 100.
2 Instruction to candidates: Your program code and output for each of Task 1 to 4.3 should b e saved in a single .ipynb file using Jupyter Notebook. For example, your program code and output for Task 1 should be saved as: TASK1_<your name>_<centre number>_<index number>.ipynb Make sure that each of your .ipynb files shows the required output in Jupyter Notebook. 1. Name your Jupyter Notebook as: TASK1_<your name>_<centre number>_<index number>.ipynb A programmer creates a remote-controlled robot and wants to fin d out how many steps it takes to exit a maze. The maze is represented by a 6 by 6 square grid. Each position in the grid is represented by a pair of coordinates. The top left square display has x = 0 and y = 0. The robot moves left, right, up or down according to a directio n entered. The following are valid inputs: Input character Action 'U' Robot moves up 'D' Robot moves down 'L' Robot moves left 'R' Robot moves right ' ' (empty string) Conti nue with previous move. If no previous move, do nothing When a direction is entered, the robot moves one position in th at direction. After the robot moves, the position it was previously on is replaced by a ' X'. The robot cannot move to the same spot twice. If the direction would place the robot on a wa ll or a position previously stepped on, the robot does not move. The maze is displayed after each move. The robot is denoted by 'T', the walls '#' and empty space '.'. # # # # T # # . # . . # # . . . # # # # . # . # # . . . . # # # # # # #
3 For each of the sub-tasks, add a comment statement at the begin ning of the code, using the hash symbol '#' to indicate the sub-task the program code belongs to, for example: In [1]: Output: Task 1.1 Using the maze given in MAZE.txt, write program code to: read the maze from the text file and store it in a suitable array structure randomize the exit along the last row of the maze update the exit square on the grid with a '.' display the maze when the robot is in its initial position at x = 4 and y = 0. [6] Test the program and show the output. Task 1.2 Add to your program code to: take in and validate a direction calculate a new position check if this position is an empty space ('.') update the grid so that the previous position of 'T' is replaced with a 'X' and the robot is located in its new position display the maze continue this until the robot is moved to the exit of the maze when robot is at the exit, the number of steps taken is displayed. [14] Test run the program. # Task 1.1 Program code
4 Below shows part of a sample run. # # # # T # # . # . . # # . . . # # # # . # . # # . . . . # # # # # . # Enter direction ('U','D','L','R',''): D # # # # X # # . # . T # # . . . # # # # . # . # # . . . . # # # # # . # Enter direction ('U','D','L','R',''): R Can't go there! # # # # X # # . # . T # # . . . # # # # . # . # # . . . . # # # # # . # Enter direction ('U','D','L','R',''): L # # # # X # # . # T X # # . . . # # # # . # . # # . . . . # # # # # . # . . . . . . . Enter direction ('U','D','L','R',''): R # # # # X # # . # X X # # . X X # # # # X # . # # . X T . # # # # # . #
5 Enter direction ('U','D','L','R',''): # # # # X # # . # X X # # . X X # # # # X # . # # . X X T # # # # # . # Enter direction ('U','D','L','R',''): D # # # # X # # . # X X # # . X X # # # # X # . # # . X X X # # # # # T # The robot takes 9 moves to exit the maze. Save your Jupyter Notebook for Task 1.
6 2. Name your Jupyter Notebook as: TASK2_<your name>_<centre number>_<index number>.ipynb This task is to perform sorting algorithms on Person objects held in a 1-dimensional array. For each of the sub-tasks, add a comment statement at the begin ning of the code, using the hash symbol ‘#’ to indicate the sub-task the program code belongs to, for example: In [1]: Output: Task 2.1 The class Person contains two properties: name - stored as a string age - stored as an integer Write program code to declare the class Person and its constructor and print() method to output the name and age of a Person object. [2] Task 2.2 Write a function task2_2(filename) that: takes a string filename which represents the name of a text file reads in the contents of the text file returns the content as a list of Person objects. Call the function task2_2 with the file PERSON.txt and print Person objects using the following statements: list_of_person = task2_2('PERSON.txt') for person in list_of_person: person.print() [4] # Task 2.1 Program code
7 Task 2.3 One method of sorting is the insertion sort. Write a function task2_3(list_of_person, key, order) that: accepts three parameters: list_of_person contains a list of Person objects key should be one of the values: o name – list to be sorted by name o age – list to be sorted by age order should be one of the values: o asc – list to be sorted by key in ascending order o desc – list to be sorted by key in descending order sorts list_of_person by key in order using insertion sort. Call the function task2_3 with the contents of the file PERSON.txt and print the sorted Person objects using the following statements: list_of_person = task2_2('PERSON.txt' ) task2_3(list_of_person, 'name', 'asc') for person in list_of_person: person.print() [8] Task 2.4 Another method of sorting is the quick sort. Write a function task2_4(list_of_person, key, order) that: accepts three parameters: list_of_person contains a list of Person objects key should be one of the values: o name – list to be sorted by name o age – list to be sorted by age order should be one of the values : o asc – list to be sorted by key in ascending order o desc – list to be sorted by key in descending order sorts list_of_person by key in order using quick sort.
8 Call the function task2_4 with the contents of the file PERSON.txt and print the sorted Person objects using the fo
Content continues in the PDF. Download PDF
Related notes
- 2024 ACJC Computing PromoExam Papers · 2024
- 2023 ACJC Promo QPExam Papers · 2023
- 2022 ACJC Computing Promo Paper 2Exam Papers · 2022
- 2021 ACJC Computing Promo Paper 2Exam Papers · 2021
- 1992 AJC Computing QPExam Papers · 1992
- 2023 YIJC P2 Question PaperExam Papers · 2023
- 2023 YIJC P1 Question PaperExam Papers · 2023
- 2023 RVHS P2 CombinedExam Papers · 2023
- 2023 RI P2 Question PaperExam Papers · 2023
- 2023 RI P1 Question PaperExam Papers · 2023
- 2023 NYJC-VJC-TJC P2 Question PaperExam Papers · 2023
- 2023 NJC P2 Question PaperExam Papers · 2023
- See all H2 Computing notes

