Question 6
OCR Computer Science June 2023 Computational thinking, algorithms and programming (J277-02)GCSE30 marks
On the specification
- (a)
- 2.2 Programming fundamentals
- (b)
- 2.2 Programming fundamentals
- (c)(i)
- 2.2 Programming fundamentals
- (c)(ii)
- 2.2 Programming fundamentals
- (c)(iii)
- 2.2 Programming fundamentals
- (c)(iv)
- 2.2 Programming fundamentals
- (c)(v)
- 2.2 Programming fundamentals
- (d)
- 2.2 Programming fundamentals
Question text
6 OCR Security Services is a company that installs intruder alarm systems in commercial buildings. The systems use a computer that is connected to the door sensors and window sensors. The following data is stored in the system: Data stored Variable identifier Example data The user’s name UserName Admin123 A telephone number to call when EmergencyPhoneNumber +449999999999 the alarm is activated Whether a door sensor is DoorSensorActive True activated Whether a window sensor is WindowSensorActive True activated A timer that counts, to the nearest second, how long a door sensor DoorActiveTime 100 has been activated A timer that counts, to the nearest second, how long a window WindowActiveTime 100 sensor has been activated Whether the system is armed SystemArmed True Whether the system is in test TestModeActive True mode (a) Below is a table showing some variables within the program. Tick (3) one box in each row to identify the most appropriate data type for each variable. Variable Boolean Char String Integer Real UserName EmergencyPhoneNumber DoorSensorActive DoorActiveTime [4] (b) The alarm has an algorithm that decides whether to sound the alarm by checking the data that is stored in the following three variables. • SystemArmed • DoorSensorActive • WindowSensorActive The alarm will only sound when the alarm has been activated and one or both of the door and window sensors are activated. When the system needs to sound the alarm it calls the pre-written procedure SoundAlarm() Write a program that checks the data in the variables and calls SoundAlarm() when appropriate. You must use either: • OCR Exam Reference Language, or • A high-level programming language that you have studied. [4] (c) The alarm system can also have motion sensors. Each type of sensor has a code. The code for each sensor is given in the table: Code Sensor MS Motion sensor DS Door sensor WS Window sensor A program is written to reset the sensors. The program: • asks the user to enter the code for the sensor they want to reset • calls the prewritten function CheckSensorCode() to check whether the code entered is a valid code • the sensor number is read as input if the code is valid and the function ResetSensor() is called for the sensor 1 sensorType = input("Enter code of the type of sensor to reset") 2 if(CheckSensorCode(sensorType)) then 3 sensorNumber = input("Please input the number of the sensor to reset") 4 sensorID = sensorType + sensorNumber 5 ResetSensor(sensorID) 6 endif (i) Give the line number where there is concatenation. [1] (ii) Give the identifier of a variable used in the program. [1] (iii) Identify the data type of the data returned by the function CheckSensorCode() [1] (iv) Give the line number that contains a function call. [1] (v) Identify two programming constructs that have been used in the program. 1 2 [2] (d) The alarm system has a log that stores a record each time a sensor is triggered. This is called an event. The record format is given in the table: Fieldname Description Date The date the event happened SensorID The sensor that was activated SensorType The type of sensor that was activated – Door, Motion or Window Length The number of seconds the sensor was triggered (to the nearest second) The log is stored in a database table called events. The current contents of events is shown: Date SensorID SensorType Length 05/02/2023 WS2 Window 38 05/02/2023 MS1 Motion 2 06/02/2023 DS3 Door 1 06/02/2023 MS2 Motion 3 06/02/2023 MS1 Motion 2 07/02/2023 WS1 Window 24 07/02/2023 DS1 Door 1 Write an SQL statement to display the sensor IDs of the door sensors that have been triggered for more than 20 seconds. [3] (e) A program written in a high-level language is used to access the data from the database. This program has a procedure, SaveLogs(), that stores the data to an external text file. The procedure SaveLogs(): • takes the string of data to be stored to the text file as a parameter • takes the filename of the text file as a parameter • stores the string of data to the text file. Write the procedure SaveLogs() You must use either: • OCR Exam Reference Language, or • A high-level programming language that you have studied. [6] (f) OCR Security Services need to identify the total number of seconds the sensors have been activated on a specific date. The data from the database table events is imported into the program written in a high- level programming language. The program stores the data in a two-dimensional (2D) string array with the identifier arrayEvents The data to be stored is shown in the table. Date SensorID SensorType Length 05/02/2023 WS2 Window 38 05/02/2023 MS1 Motion 2 06/02/2023 DS3 Door 1 06/02/2023 MS2 Motion 3 06/02/2023 MS1 Motion 2 07/02/2023 WS1 Window 24 07/02/2023 DS1 Door 1 In this table, the value of events[1, 1] contains "MS1". (i) An array can only store data of one data type. Any non-string data must be converted to a string before storing in the array. Identify the process that converts integer data to string data. [1] (ii) Write a program that: • asks the user to input a date • totals the number of seconds sensors have been activated on the date input • outputs the calculated total in an appropriate message including the date, for example: Sensors were activated for 40 seconds on 05/02/2023 You must use either: • OCR Exam Reference Language, or • A high-level programming language that you have studied. [6]