Question 5

AQA Computer Science June 2022 Paper 1A (8525/1A)GCSE5 marks

On the specification

5.1
3.2 Programming
5.2
3.2 Programming
5.3
3.2 Programming
Question text

5 A programmer has started to write a program using C#. Their program is shown in box Figure 6. The program should generate and output 10 numbers, each of which is randomly selected from the numbers in a data structure called numbers. The program uses the Random class. For example, r.Next(0, 8) would generate a random integer between 0 and 7 inclusive. One possible output from the finished program would be 11, 14, 14, 42, 2, 56, 56, 14, 4, 2 • Line numbers are included but are not part of the program. Figure 6 1 int[] numbers = { 11, 14, 56, 4, 12, 6, 42, 2 }; 2 int count = 0; 3 Random r = new Random(); 4 while (count < 10) { 5 count = count + 1; 6 int number = r.Next(0, 8; 7 Console.WriteLine(numbers[count]); 8 } 5.1 The program shown in Figure 6 contains a syntax error. Shade two lozenges to indicate the statements that are true about syntax errors. [2 marks] A syntax error can be found by testing boundary values in a A program. B A syntax error is a mistake in the grammar of the code. C A syntax error is generally harder to spot than a logic error. D A syntax error will stop a program from running. E An example of a syntax error is trying to access the fifth character in a string which only contains four characters. 5.2 box The program shown in Figure 6 also contains a logic error. Identify the line number that contains the logic error, and correct this line of the program. Your corrected line must be written in C#. [2 marks] Line number Corrected line 5.3 What type of data structure is the variable numbers? [1 mark]