Question 2
OCR Computer Science June 2018 Paper 2AS43 marks
On the specification
- (a)(i)
- 1.4 Data types, data structures and algorithms
- (a)(ii)
- 1.4 Data types, data structures and algorithms
- (a)(iii)
- 1.4 Data types, data structures and algorithms
- (b)
- 2.2 Problem solving and programming
- (c)(i)
- 2.2 Problem solving and programming1.4 Data types, data structures and algorithms
- (c)(ii)
- 2.2 Problem solving and programming1.4 Data types, data structures and algorithms
- (d)(i)
- 2.3 Algorithms
- (d)(ii)
- 2.3 Algorithms
- (d)(iii)
- 2.3 Algorithms2.2 Problem solving and programming
- (d)(iv)
- 2.3 Algorithms
Question text
2 A games company has developed a game called Kidz Arrowz. The players throw an arrow at a target board and are awarded different points depending on which circle the arrow lands. Fig. 1 shows the board. 1 3 6 10 Fig. 1 A computer program is required to keep track of the scores for each competition. The user will enter the number of players, and the name of each player, in that competition to a maximum of 10. The program will then ask for the score of each player in turn. Each competition has 8 rounds, with each player throwing one arrow each round. The program will then display the total score of each player. (a) (i) The players are declared as a record structure: record player(string playerName, integer totalScore) Describe what is meant by a record structure. [2] (ii) The records for the players are stored in a 1D array. State why a 1D array is a suitable data structure for the records. [1] (iii) Three data structures are arrays, records and stacks. Identify one other data structure. [1] (b) The program is decomposed into multiple sub-programs, that each perform a specific task. The array, scores, is declared as a global array of type record: global array scores[10] of player Explain why the array scores has been declared as global instead of local. [2] (c) Player 1 is named Johnny. In the first round Johnny scores 3. Johnny can be added to the array using the code: scores[0].playerName = "Johnny" scores[0].totalScore = 3 (i) Write an algorithm to: • allow the user to input and validate the number of players • allow the user to input the name of each player • output the round number at the start of a round • display the player number for the score that needs to be entered • allow the user to input the score for each player in that round and add it to their total. [7] (ii) Write an algorithm to output: • the total score of each player with their name e.g. Johnny scored 38 • the average (mean) score of each player over the 8 rounds, with their name e.g. If Johnny’s total score is 38, then Johnny’s average is 4.75. [4] (d) (i) The programmer has decided to use a bubble sort to sort the players’ scores in descending order of score. Describe the disadvantages of using a bubble sort. [2] (ii) Despite the disadvantages, the programmer has decided to use a bubble sort for the players’ scores. Identify the characteristic of this problem that minimises the disadvantages of a bubble sort. [1] (iii) Write a procedure, sortScores, to perform a bubble sort on the global array scores to sort the players’ scores into descending numeric order. [6] (iv) An alternative sorting method is the insertion sort. A procedure, insertionSort, has been written to sort an array numbers. The procedure is incomplete. Complete the procedure. procedure insertionSort() for count = 0 to numbers.length - 1 position = while position > 0 and numbers[position] < numbers[position-1] temp = numbers[position-1] = numbers[position] = temp position = endwhile next count endprocedure [4] (e) The programmer uses an Integrated Development Environment (IDE) to develop the program. Describe how the IDE could be used to create the Kidz Arrowz program. [3]