Question 5
OCR Computer Science June 2022 Computational thinking, algorithms and programming (J277-02)GCSE30 marks
On the specification
- (a)(i)
- 2.2 Programming fundamentals
- (a)(ii)
- 2.2 Programming fundamentals
- (a)(iii)
- 2.2 Programming fundamentals
- (b)(i)
- 2.3 Producing robust programs
- (b)(ii)
- 2.3 Producing robust programs
- (c)(i)
- 2.2 Programming fundamentals
- (c)(ii)
- 2.2 Programming fundamentals
- (d)
- 2.3 Producing robust programs
- (e)
- 2.1 Algorithms2.2 Programming fundamentals
Question text
5 Customers at a hotel can stay between 1 and 5 (inclusive) nights and can choose between a basic room or a premium room. (a) A typical booking record is shown in the table: firstName Amaya surname Taylor-Ling nights 3 room Premium stayComplete False (i) State the most appropriate data type for the following fields: Nights Room [2] (ii) Give the name of one field that could be stored as a Boolean data type. [1] (iii) Booking records are stored in a database table called TblBookings. The following SQL statement is written to display all customer bookings that stay more than one night. SELECT ALL FROM TblBookings IF Nights < 1 The SQL statement is incorrect. Rewrite the SQL statement so that it is correct. [4] (b) When a new booking is recorded, the details are entered into a program to validate the values. The following criteria are checked: • firstName and surname are not empty • room is either “basic” or “premium” • nights is between 1 and 5 (inclusive). If any invalid data is found “NOT ALLOWED” is displayed. If all data is valid “ALLOWED” is displayed. (i) Complete the following program to validate the inputs. You must use either: • OCR Exam Reference Language, or • a high-level programming language that you have studied. firstName = input("Enter a first name") surname = input("Enter a surname") room = input("Enter basic or premium") nights = input("Enter between 1 and 5 nights") stayComplete = False [5] (ii) Complete the following test plan to check whether the number of nights is validated correctly. Test data Type of test Expected output (number of nights) 2 ALLOWED Boundary ALLOWED Erroneous / Invalid NOT ALLOWED [3] (c) A Basic room costs £60 each night. A Premium room costs £80 each night. (i) Create a function, newPrice(), that takes the number of nights and the type of room as parameters, calculates and returns the price to pay. You do not have to validate these parameters. You must use either: • OCR Exam Reference Language, or • a high-level programming language that you have studied. [4] (ii) Write program code, that uses newPrice(), to output the price of staying in a Premium room for 5 nights. You must use either: • OCR Exam Reference Language, or • a high-level programming language that you have studied. [3] (d) The hotel has nine rooms that are numbered from room 0 to room 8. The number of people currently staying in each room is stored in an array with the identifier room. The index of room represents the room number. Array room Index 0 1 2 3 4 5 6 7 8 Data 2 1 3 2 1 0 0 4 1 The following program counts how many people are currently staying in the hotel. for count = 1 to 8 total = 0 total = total + room[count] next count print(total) When tested, the program is found to contain two logic errors. Describe how the program can be refined to remove these logic errors. [2] (e) The hotel car park charges £4 per hour. If the car is electric, this price is halved to £2 per hour. Write an algorithm to: • take as input the number of hours the user has parked and whether their car is electric or not • calculate and output the total price • repeat continually until the user enters 0 hours. You must use either: • OCR Exam Reference Language, or • a high level programming language that you have studied. [6]