4. Further Problem-solving and Programming Skills
A section of Computer Science, 9608
Listing 8 of 8 questions
A bank has 95 000 customers. Each customer has a unique ID. When a customer uses an Automated Teller Machine (ATM) to obtain cash, their current balance is checked. The balance is stored in a file which has the following fields: • the customer ID (6-digit number in the range 100000 to 999999) • an encrypted PIN • the current balance The file can store a maximum of 100 000 records. Give a reason why a random organisation would be appropriate for this file. An algorithm for inserting a new record in this file uses the following hash function: RecordKey CustomerID MOD 100000 where RecordKey is the record position in the file. Complete the table to show the values generated by the hash function for the given customer IDs. CustomerID RecordKey State the range of possible values for RecordKey. Minimum value of RecordKey: Maximum value of RecordKey: A procedure is written to insert a new record into the file. Complete the algorithm for this procedure. PROCEDURE InsertRecord(CustomerID : INTEGER) RecordKey CustomerID MOD 100000 Success FALSE // Find position for new record and insert it REPEAT IF record at position RecordKey is ……………………… THEN Insert new record at position RecordKey Success TRUE ELSE IF RecordKey = ……………………… THEN RecordKey ……………………… ELSE RecordKey ……………………… + 1 ENDIF ENDIF UNTIL Success = TRUE ENDPROCEDURE Explain why an encrypted version of the PIN is stored in the file. A customer attempts to withdraw cash from an ATM. An algorithm is used to check if the customer has entered the correct PIN. Complete the algorithm. 1. Customer ID is read from card. 2. Customer enters PIN. 3. Customer PIN is 4. 5. Customer record is located in file. 6. 7. If match then transaction can proceed.
9608_s17_qp_31
THEORY
2017
Paper 3, Variant 1
A bank has 95 000 customers. Each customer has a unique ID. When a customer uses an Automated Teller Machine (ATM) to obtain cash, their current balance is checked. The balance is stored in a file which has the following fields: • the customer ID (6-digit number in the range 100000 to 999999) • an encrypted PIN • the current balance The file can store a maximum of 100 000 records. Give a reason why a random organisation would be appropriate for this file. An algorithm for inserting a new record in this file uses the following hash function: RecordKey CustomerID MOD 100000 where RecordKey is the record position in the file. Complete the table to show the values generated by the hash function for the given customer IDs. CustomerID RecordKey State the range of possible values for RecordKey. Minimum value of RecordKey: Maximum value of RecordKey: A procedure is written to insert a new record into the file. Complete the algorithm for this procedure. PROCEDURE InsertRecord(CustomerID : INTEGER) RecordKey CustomerID MOD 100000 Success FALSE // Find position for new record and insert it REPEAT IF record at position RecordKey is ……………………… THEN Insert new record at position RecordKey Success TRUE ELSE IF RecordKey = ……………………… THEN RecordKey ……………………… ELSE RecordKey ……………………… + 1 ENDIF ENDIF UNTIL Success = TRUE ENDPROCEDURE Explain why an encrypted version of the PIN is stored in the file. A customer attempts to withdraw cash from an ATM. An algorithm is used to check if the customer has entered the correct PIN. Complete the algorithm. 1. Customer ID is read from card. 2. Customer enters PIN. 3. Customer PIN is 4. 5. Customer record is located in file. 6. 7. If match then transaction can proceed.
9608_s17_qp_33
THEORY
2017
Paper 3, Variant 3
Data types can be defined in a programming language. The data type, StudentRecord, is defined by the code: TYPE StudentRecord DECLARE StudentID : INTEGER DECLARE StudentFirstName : STRING DECLARE StudentSurname : STRING DECLARE StudentDOB : DATE DECLARE StudentCourse : ARRAY[1:10] OF STRING ENDTYPE A variable, CollegeStudent, is declared with the code: DECLARE CollegeStudent : StudentRecord Write a pseudocode statement to assign 6539 to the StudentID of CollegeStudent. The type definition for StudentRecord is changed. Students can take six courses from: Computer Science, Engineering, Science, Maths, Physics, Chemistry, Music, Drama and English Language. Rewrite one line from the type definition of StudentRecord to implement the change. DECLARE The values for the field StudentID must be between 1 and 8000 inclusive. Rewrite one line from the type definition of StudentRecord to implement the change. DECLARE A programmer is asked to write a program to process the assessment data for each student. Students sit one exam in every course they take. A composite data type, StudentAssessment, needs to be defined with the following three fields. • a student assessment code (a unique code of three letters and two digits) • the marks for the six exams • the average mark of the six exams Write pseudocode to define the data type StudentAssessment. Data about all students and their assessments are stored in a file that uses random organisation. The StudentID is used as the key field. The program allows a user to enter data for a new student. Explain how the program adds the new data to the file.
9608_s18_qp_32
THEORY
2018
Paper 3, Variant 2
Questions Discovered
8