9618/43

Computer Science 9618/43May/June 2022

Cambridge A-Level · Practical · worked solutions for every part, with the mark scheme

3
questions
75
marks
150
minutes

Topics Programming Paradigms (Procedural and Object-oriented) · Algorithms and Abstract Data Types · File Processing and Exception Handling

Q1Programming Paradigms (Procedural and Object-oriented)File Processing and Exception HandlingAlgorithms and Abstract Data TypesFree sample

The text file HighScore.txt stores the players who have scored the top ten scores in a game, in descending order of score. The file stores the 3-character name of the player, and their integer score, in the order: player, score.

For example, the current top player in the text file:

FYI is the player name

10000 is the score

The program:

• reads in the data from HighScore.txt
• allows the user to enter a new player name and their score
• if appropriate, inserts the new player (name and score) into the top ten
• writes the top ten players (name and score) into a new text file NewHighScore.txt

(a)

The program stores the players and their scores in an array of 11 elements (10 elements to be read from the file, 1 element to be inserted by the user).

Write a program to declare one or more arrays, as global data structures, to store the player names and their scores.

Save your program as Question1_J2022.

Copy and paste the program code into part 1(a) in the evidence document.

2M
(b)

The procedure ReadHighScores() opens the file HighScore.txt and reads the data into the data structure(s) declared in part 1(a).

Write program code to declare the procedure ReadHighScores().

Save your program.

Copy and paste the program code into part 1(b) in the evidence document.

6M
(c)

The procedure OutputHighScores() outputs all the values in the data structure(s) in the format:

PlayerName Score

For example, the first two data items:

FYI 10000
ABC 9092

Write program code to declare the procedure OutputHighScores().

Save your program.

Copy and paste the program code into part 1(c) in the evidence document.

3M
(d)

The main program should first call ReadHighScores() and then OutputHighScores().

(i)

Write the program code for the main program.

Save your program.

Copy and paste the program code into part 1(d)(i) in the evidence document.

2M
(ii)

Test your program.

Take a screenshot to show the output from part 1(d)(i).

Copy and paste the screenshot into part 1(d)(ii) in the evidence document.

1M
(e)

The main program needs to ask the user to input a new player name and a score. If this score is in the top ten then it will create a new top ten list that includes this score.

(i)

Amend the main program to ask the user to input a 3-character player name and an integer score that must be between 1 and 100 000 inclusive.

Save your program.

Copy and paste the program code into part 1(e)(i) in the evidence document.

3M
(ii)

Write program code to declare a procedure that:

• takes the player name and score as parameters
• creates a new top ten list that includes the parameter if appropriate.

Save your program.

Copy and paste the program code into part 1(e)(ii) in the evidence document.

5M
(iii)

Amend the main program to call the procedure from part 1(e)(ii).

Output the contents of the array before inserting the new player name and score, and output the contents of the array after inserting the new player name and score.

Save your program.

Copy and paste the program code into part 1(e)(iii) in the evidence document.

2M
(iv)

Test your program by entering the player name "JKL" and the score "9999".

Take a screenshot to show the output.

Copy and paste the screenshot into part 1(e)(iv) in the evidence document.

1M
(f)

The procedure WriteTopTen() stores the new top ten player names and scores in a text file called NewHighScore.txt

Write program code to declare the procedure WriteTopTen().

Save your program.

Copy and paste the program code into part 1(f) in the evidence document.

4M

The rest of this paper

2 more questions
  • Q2Programming Paradigms (Procedural and Object-oriented)25M
  • Q3Programming Paradigms (Procedural and Object-oriented) · Algorithms and Abstract Data Types21M
Loading the full paper…