Question 8

OCR Computer Science Specimen Paper 2GCSE30 marks

On the specification

(a)
2.2 Programming fundamentals
(b)(i)
2.2 Programming fundamentals2.3 Producing robust programs
(b)(ii)
2.3 Producing robust programs
(c)
2.2 Programming fundamentals
(d)
2.1 Algorithms2.2 Programming fundamentals
(e)
2.1 Algorithms2.2 Programming fundamentals
(f)
2.2 Programming fundamentals2.3 Producing robust programs
Question text

8 A teacher researches the length of time students spend playing computer games each day. (a) Tick () one box to identify the data type you would choose to store the data and explain why this is a suitable data type. Data Type Tick () one box String Integer Real Boolean Explanation: (b) The program should only allow values from 0 to 300 inclusive as valid inputs. If the data entered breaks this validation rule, an error message is displayed. (i) Complete the following program to output "Invalid input" if the data does not meet the validation rule. You must use either: • OCR Exam Reference Language, or • a high-level programming language that you have studied. mins = input("Enter minutes played: ") if mins < 0 mins then ("Invalid input") endif (ii) Complete the following test plan for the program in 8(b)(i). Test data Test type Expected result 25 Normal Value accepted Invalid input Invalid message displayed 300 Boundary (c) Data for one week (Monday to Friday) is stored in a 2D array with the identifier minsPlayed. The following table shows part of this array, containing 4 students. Students Stuart Wes Victoria Dan 1 2 3 Days Mon 0 60 30 45 0 of the week Tue 1 180 60 0 60 Wed 2 200 30 0 20 Thu 3 60 10 15 15 Fri 4 100 35 30 45 The teacher wants to output the number of minutes Dan (column index 3) played computer games on Wednesday (row index 2). The following code is written: print(minsPlayed[3,2]) Write a line of code to output the number of minutes that Stuart played computer games on Friday. You must use either: • OCR Exam Reference Language, or • a high-level programming language that you have studied. [1] (d) The teacher writes a program to add up and print out the total number of minutes student 2 played computer games over 5 days (Monday to Friday). total = 0 total = total + minsPlayed[2,0] total = total + minsPlayed[2,1] total = total + minsPlayed[2,2] total = total + minsPlayed[2,3] total = total + minsPlayed[2,4] print(total) Refine the program to be more efficient. Write the refined version of the algorithm. You must use either: • OCR Exam Reference Language, or • a high-level programming language that you have studied. (e) The following program uses a condition-controlled loop. x = 15 y = 0 while x > 0 y = y + 1 x = x – y endwhile print(y) Complete the trace table to test this program. x y output (f) A teacher writes an algorithm to store the name of the game a student plays each night (for example "OCR Zoo Simulator"). variable.length returns the number of characters in variable. variable.upper returns the characters in variable in upper case. valid = false while(valid == false) gameName = input("Enter the game name") if (gameName.length > 0) AND (gameName.length < 20) gamesPlayed = gameName.upper valid = true print("Valid game name") else print("Game name is not valid") endif endwhile The algorithm needs testing to make sure the IF-ELSE statement works correctly. Identify two different pieces of test data that can be used to test different outputs of the algorithm. Give the output from the program for each piece of test data. Test data 1 Expected output Test data 2 Expected output (g) The teacher asks students how long they spend completing homework. Students answer in minutes and hours (for example 2 hours 15 minutes). The teacher would like to create an algorithm that will display students’ inputs in minutes only. (i) Identify the input and output required from this algorithm. Input Output (ii) A program is created to convert hours and minutes into a total number of minutes. The teacher wants to create a sub program to perform the calculation. The program has been started but is not complete. Complete the design for the program. hours = input("Please enter number of hours played") minutes = input("Please enter number of minutes played") finalTotal = print(finalTotal) function endfunction (iii) The following flowchart outputs a message depending on how long each person has spent playing computer games. Rewrite the flowchart as a program. You must use either: • OCR Exam Reference Language, or • a high-level programming language that you have studied.