Question 2
OCR Computer Science June 2022 Computational thinking, algorithms and programming (J277-02)GCSE19 marks
On the specification
- (a)(i)
- 2.4 Boolean logic
- (a)(ii)
- 2.4 Boolean logic
- (a)(iii)
- 2.4 Boolean logic
- (b)
- 2.1 Algorithms
- (c)
- 2.1 Algorithms
- (d)(i)
- 2.2 Programming fundamentals
- (d)(ii)
- 2.1 Algorithms2.2 Programming fundamentals
Question text
2 A fast food restaurant offers half-price meals if the customer is a student or has a discount card. The offer is not valid on Saturdays. A computer system is used to identify whether the customer can have a half-price meal. The table identifies the three inputs to the computer system: Input Value A Is a student B Has a discount card C The current day is Saturday (a) The logic system P = (A OR B) AND NOT C is used. (i) Complete the following logic diagram for P = (A OR B) AND NOT C by drawing one logic gate in each box. A B P C [3] (ii) A truth table can be produced for this logic circuit. Describe the purpose of a truth table. [2] (iii) State how many rows (excluding any headings) would be required in a truth table for the logic expression: P = (A OR B) AND NOT C [1] (b) The restaurant needs an algorithm designing to help employees work out if a customer can have a half price meal or not. It should: • input required data • decide if the customer is entitled to a discount • output the result of the calculation. Design the algorithm using a flowchart. [5] (c) The restaurant adds a service charge to the cost of a meal depending on the number of people at a table. If there are more than five people 5% is added to the total cost of each meal. Customers can also choose to leave a tip, this is optional and the customer can choose between a percentage of the cost, or a set amount. Identify all the additional inputs that will be required for this change to the algorithm. [2] (d) Each member of staff that works in the restaurant is given a Staff ID. This is calculated using the following algorithm. 1 surname = input("Enter surname") 2 year = input("Enter starting year") 3 staffID = surname + str(year) 4 while staffID.length < 10 5 staffID = staffID + "x" 6 endwhile 7 print("ID " + staffID) (i) Define the term casting and give the line number where casting has been used in the algorithm. Definition Line number [2] (ii) Complete the following trace table for the given algorithm when the surname “Kofi” and the year 2021 are entered. You may not need to use all rows in the table. Line surname year staffID Output 1 Kofi 2 2021 [4]